Class: Rolify::Generators::UserGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/rolify/user_generator.rb

Instance Method Summary collapse

Instance Method Details

#inject_rolify_methodObject



18
19
20
21
22
23
24
# File 'lib/generators/rolify/user_generator.rb', line 18

def inject_rolify_method
  if options.orm == :active_record
    /class #{class_name.camelize}\n|class #{class_name.camelize} .*\n|class #{class_name.demodulize.camelize}\n|class #{class_name.demodulize.camelize} .*\n/
  else
    /include Mongoid::Document\n|include Mongoid::Document .*\n/
  end
end

#inject_user_contentObject



12
13
14
15
16
# File 'lib/generators/rolify/user_generator.rb', line 12

def inject_user_content
  inject_into_file(model_path, :after => inject_rolify_method) do
    "  rolify#{role_association}\n"
  end
end

#model_pathObject



26
27
28
# File 'lib/generators/rolify/user_generator.rb', line 26

def model_path
  File.join("app", "models", "#{file_path}.rb")
end

#role_associationObject



30
31
32
33
34
35
36
# File 'lib/generators/rolify/user_generator.rb', line 30

def role_association
  if role_cname != "Role"
    " :role_cname => '#{role_cname.camelize}'"
  else
    ""
  end
end