Module: RoleMaking

Defined in:
lib/role_making.rb,
lib/role_making/role.rb,
lib/role_making/railtie.rb,
lib/role_making/version.rb,
lib/role_making/resourcing.rb,
lib/generators/role_making_generator.rb

Defined Under Namespace

Modules: Generators, Resourcing, Role Classes: Railtie

Constant Summary collapse

VERSION =
"0.2.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#role_cnameObject

Returns the value of attribute role_cname.



6
7
8
# File 'lib/role_making.rb', line 6

def role_cname
  @role_cname
end

#role_join_table_nameObject

Returns the value of attribute role_join_table_name.



6
7
8
# File 'lib/role_making.rb', line 6

def role_join_table_name
  @role_join_table_name
end

#role_table_nameObject

Returns the value of attribute role_table_name.



6
7
8
# File 'lib/role_making.rb', line 6

def role_table_name
  @role_table_name
end

Instance Method Details

#role_making(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/role_making.rb', line 8

def role_making(options = {})
  include Role
  #extend Dynamic if RoleMaking.dynamic_shortcuts

  options.reverse_merge!({:role_cname => 'Role'})
  self.role_cname = options[:role_cname]
  self.role_table_name = self.role_cname.tableize.gsub(/\//, "_")

  default_join_table = [self.to_s.tableize.gsub(/\//, "_"),self.role_table_name].sort.join("_")
  options.reverse_merge!({:role_join_table_name => default_join_table})
  self.role_join_table_name = options[:role_join_table_name]

  rolify_options = { :class_name => options[:role_cname].camelize }
  rolify_options.merge!({ :join_table => self.role_join_table_name })
  rolify_options.merge!(options.reject{ |k,v| ![ :before_add, :after_add, :before_remove, :after_remove ].include? k.to_sym })

  has_and_belongs_to_many :roles, **rolify_options
  #has_and_belongs_to_many :roles, class_name: 'role', join_table: 'roles_users'

  #load_dynamic_methods if RoleMaking.dynamic_shortcuts
end