Class: Devise::Customizers::UserName::AuthenticationKeys

Inherits:
Object
  • Object
show all
Extended by:
RailsAssist::UseMacro
Includes:
Cream::GeneratorHelper
Defined in:
lib/generators/devise/customize/helpers/username_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cream::GeneratorHelper

#add_logger, #debug!, included, #info!, #logit!

Constructor Details

#initialize(user_class, login_attribute) ⇒ AuthenticationKeys

Returns a new instance of AuthenticationKeys.



123
124
125
126
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 123

def initialize user_class, 
  @user_class = user_class          
  @login_attribute = 
end

Instance Attribute Details

#login_attributeObject

Returns the value of attribute login_attribute.



121
122
123
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 121

def 
  @login_attribute
end

Instance Method Details

#default_keys_stmtObject



143
144
145
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 143

def default_keys_stmt
  /# config.authentication_keys = [\s*:email\s*]/
end

#devise_init_content?(content) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 135

def devise_init_content? content
  read_initializer(:devise) =~ content.to_regexp
end

#keys_stmt_replacement(name) ⇒ Object



139
140
141
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 139

def keys_stmt_replacement name
  "config.authentication_keys = [ :#{name} ]"
end

#modify_initializerObject



128
129
130
131
132
133
# File 'lib/generators/devise/customize/helpers/username_helper.rb', line 128

def modify_initializer
  debug! 'modify devise initializer'
  return if devise_init_content? keys_stmt_replacement()

  replace_initializer_content :devise,  :where => default_keys_stmt, :with => keys_stmt_replacement()
end