Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure devise modules #59

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ $ bundle update alchemy-devise
$ bin/rails g alchemy:devise:install
```

## Devise modules

Default Devise modules included in `Alchemy::User` model

- `:database_authenticatable`
- `:trackable`
- `:validatable`
- `:timeoutable`
- `:recoverable`

If you want to add additional modules into the Alchemy user class append them to `Alchemy.devise_modules` in an initializer in your app.

### Register additional modules example

```ruby
# config/initializers/alchemy.rb
Alchemy.devise_modules << :registerable
```

### Using old encryption

If your app uses an old encryption that needs the +devise-encryptable+ gem you also need to load the devise module.

```ruby
# config/initializers/alchemy.rb
Alchemy.devise_modules << :encryptable
```

## Testing

If you want to contribute (and you should ^_^), you need to run the tests locally on your machine.
Expand Down
15 changes: 2 additions & 13 deletions app/models/alchemy/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,8 @@ class User < ActiveRecord::Base
:send_credentials,
:tag_list
]
DEVISE_MODULES = [
:database_authenticatable,
:trackable,
:validatable,
:timeoutable,
:recoverable
]
# If the app uses an old encryption it uses the devise-encryptable gem
# therefore we have to load the devise module
if (::Devise::Models::Encryptable rescue false)
DEVISE_MODULES.push(:encryptable)
end
devise *DEVISE_MODULES

devise *Alchemy.devise_modules

acts_as_taggable
acts_as_tagger
Expand Down
35 changes: 35 additions & 0 deletions lib/alchemy/devise.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
require "alchemy/devise/engine"

module Alchemy
# Devise modules included in +Alchemy::User+ model
#
# === Default modules
#
# [
#. :database_authenticatable,
# :trackable,
# :validatable,
# :timeoutable,
# :recoverable
#. ]
#
# If you want to add additional modules into the Alchemy user class append
# them to this collection in an initializer in your app.
#
# === Example
#
# # config/initializers/alchemy.rb
# Alchemy.devise_modules << :registerable
#
# If your app uses an old encryption that needs the +devise-encryptable+ gem
# you also need to load the devise module.
#
# Alchemy.devise_modules << :encryptable
#
def self.devise_modules
@devise_modules ||= [
:database_authenticatable,
:trackable,
:validatable,
:timeoutable,
:recoverable
]
end

module Devise
end
end