Class: ActiveRecord::Generators::RolifyGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/active_record/rolify_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_rolify_migrationObject



37
38
39
# File 'lib/generators/active_record/rolify_generator.rb', line 37

def copy_rolify_migration
  migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb", migration_version: migration_version
end

#ensure_user_class_definedObject



12
13
14
15
16
17
# File 'lib/generators/active_record/rolify_generator.rb', line 12

def ensure_user_class_defined
  unless user_class_defined?
    prompt_missing_user
    abort
  end
end

#generate_modelObject



19
20
21
# File 'lib/generators/active_record/rolify_generator.rb', line 19

def generate_model
  invoke "active_record:model", [ name ], :migration => false
end

#inject_role_classObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/active_record/rolify_generator.rb', line 23

def inject_role_class
  if args[1]=="engine"
    if args[2]=="devise"
      require 'devise'
      require "#{ENGINE_ROOT}/config/initializers/devise.rb"
      require "#{ENGINE_ROOT}/app/models/#{user_cname.downcase}.rb"
    else
      require "#{ENGINE_ROOT}/app/models/#{user_cname.downcase}.rb"
    end
  end

  inject_into_class(model_path, class_name, model_content)
end