Module: DeviseUserGenerator::Helper
- Included in:
- Devise::Generators::UsersGenerator
- Defined in:
- lib/generators/devise/users/helper.rb
Instance Method Summary collapse
- #admin_class_name ⇒ Object
- #create_user_model(name) ⇒ Object
- #devise_strategies ⇒ Object
- #devise_users? ⇒ Boolean
- #has_admin_model? ⇒ Boolean
- #has_devise_user?(user) ⇒ Boolean
- #has_user_model? ⇒ Boolean
- #inherit_model(hash) ⇒ Object
- #is_admin?(name) ⇒ Boolean
- #remove_inheritance(user) ⇒ Object
- #subclass(hash) ⇒ Object
- #superclass(hash) ⇒ Object
- #user_generator ⇒ Object
Instance Method Details
#admin_class_name ⇒ Object
58 59 60 |
# File 'lib/generators/devise/users/helper.rb', line 58 def admin_class_name admin_class.to_s.classify end |
#create_user_model(name) ⇒ Object
62 63 64 |
# File 'lib/generators/devise/users/helper.rb', line 62 def create_user_model name rgen "#{user_generator} #{name}" end |
#devise_strategies ⇒ Object
3 4 5 6 7 8 |
# File 'lib/generators/devise/users/helper.rb', line 3 def devise_strategies { :default => [:database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable], :admin => [:database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable] } end |
#devise_users? ⇒ Boolean
50 51 52 |
# File 'lib/generators/devise/users/helper.rb', line 50 def devise_users? has_devise_user?(user_class) && has_devise_user?(admin_class) end |
#has_admin_model? ⇒ Boolean
28 29 30 |
# File 'lib/generators/devise/users/helper.rb', line 28 def has_admin_model? has_model? admin_class.as_filename end |
#has_devise_user?(user) ⇒ Boolean
40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/devise/users/helper.rb', line 40 def has_devise_user? user return true if is_admin?(user) && !admin_class begin read_model(user.as_filename) =~ /devise/ rescue Exception => e info! "Exception for #has_devise_user? #{user}: #{e.}" false end end |
#has_user_model? ⇒ Boolean
32 33 34 |
# File 'lib/generators/devise/users/helper.rb', line 32 def has_user_model? has_model? user_class.as_filename end |
#inherit_model(hash) ⇒ Object
10 11 12 13 14 |
# File 'lib/generators/devise/users/helper.rb', line 10 def inherit_model hash class_name = subclass(hash) superclass_name = superclass(hash) File.replace_content_from model_file_name(class_name.as_filename), :where => /class #{class_name}/, :with => "class #{class_name} < #{superclass_name}" end |
#is_admin?(name) ⇒ Boolean
54 55 56 |
# File 'lib/generators/devise/users/helper.rb', line 54 def is_admin? name name.to_s.underscore == admin_class end |
#remove_inheritance(user) ⇒ Object
24 25 26 |
# File 'lib/generators/devise/users/helper.rb', line 24 def remove_inheritance user File.remove_content_from model_file_name(user.as_filename), :where => /<\s*ActiveRecord::Base/ end |
#subclass(hash) ⇒ Object
20 21 22 |
# File 'lib/generators/devise/users/helper.rb', line 20 def subclass hash hash.keys.first.to_s.camelize end |
#superclass(hash) ⇒ Object
16 17 18 |
# File 'lib/generators/devise/users/helper.rb', line 16 def superclass hash hash.values.first end |
#user_generator ⇒ Object
36 37 38 |
# File 'lib/generators/devise/users/helper.rb', line 36 def user_generator active_record? ? 'devise' : "#{orm}:devise" end |