Class: ActiveRecord::Generators::ErbacGenerator

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

Instance Method Summary collapse

Instance Method Details

#copy_erbac_migrationObject



42
43
44
# File 'lib/generators/active_record/erbac_generator.rb', line 42

def copy_erbac_migration
  migration_template "migration.rb", "db/migrate/erbac_create_auth"
end

#generate_auth_item_modelObject



30
31
32
33
# File 'lib/generators/active_record/erbac_generator.rb', line 30

def generate_auth_item_model
  Rails::Generators.invoke("active_record:model", [options.auth_item[0], "--no-migration"], behavior: behavior)
  Rails::Generators.invoke("active_record:model", [options.auth_assignment[0], "--no-migration"], behavior: behavior)
end

#init_erbac_optionsObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/active_record/erbac_generator.rb', line 17

def init_erbac_options
  # assert options.auth_item[0]
  options.auth_item[1] ||= options.auth_item[0].classify || Erbac::Configure::AUTH_ITEM_CLASS
  options.auth_item[2] ||= options.auth_item[0].tableize || Erbac::Configure::AUTH_ITEM_TABLE

  # assert options.auth_item_child[0]
  options.auth_item_child[1] || options.auth_item_child[0].tableize || Erbac::Configure::AUTH_ITEM_CHILD_TABLE

  # assert options.auth_assignment[0]
  options.auth_assignment[1] || options.auth_assignment[0].classify || Erbac::Configure::AUTH_ASSIGNMENT_CLASS
  options.auth_assignment[2] || options.auth_assignment[0].tableize || Erbac::Configure::AUTH_ASSIGNMENT_TABLE
end

#inject_auth_item_modelObject



35
36
37
38
39
40
# File 'lib/generators/active_record/erbac_generator.rb', line 35

def inject_auth_item_model
  if behavior == :invoke
    inject_into_class(model_path(options.auth_item[0]), options.auth_item[1], "  control_auth_item\n")
    inject_into_class(model_path(options.auth_assignment[0]), options.auth_assignment[1], "  control_auth_assignment\n")
  end
end