Module: Rbacfull

Extended by:
Configure
Defined in:
lib/rbacfull.rb,
lib/rbacfull/version.rb,
lib/generators/rbacfull/install_generator.rb

Defined Under Namespace

Classes: InstallGenerator

Constant Summary collapse

VERSION =
"0.1.2"
@@resource_types =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



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

def adapter
  @adapter
end

#resource_adapterObject

Returns the value of attribute resource_adapter.



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

def resource_adapter
  @resource_adapter
end

#role_cnameObject

Returns the value of attribute role_cname.



6
7
8
# File 'lib/rbacfull.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/rbacfull.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/rbacfull.rb', line 6

def role_table_name
  @role_table_name
end

Class Method Details

.resource_typesObject



65
66
67
# File 'lib/rbacfull.rb', line 65

def self.resource_types
  @@resource_types
end

Instance Method Details

#rbacfull(options = {}) ⇒ Object



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

def rbacfull(options = {})
  include Role
  extend Dynamic if Rbacfull.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}"
  options.reverse_merge!({:role_join_table_name => default_join_table})
  self.role_join_table_name = options[:role_join_table_name]

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

  has_and_belongs_to_many :roles, rbacfull_options

  self.adapter = Rbacfull::Adapter::Base.create("role_adapter", self.role_cname, self.name)
  load_dynamic_methods if Rbacfull.dynamic_shortcuts
end

#resourcify(association_name = :roles, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rbacfull.rb', line 36

def resourcify(association_name = :roles, options = {})
  include Resource

  options.reverse_merge!({ :role_cname => 'Role', :dependent => :destroy })
  resourcify_options = { :class_name => options[:role_cname].camelize, :as => :resource, :dependent => options[:dependent] }
  self.role_cname = options[:role_cname]
  self.role_table_name = self.role_cname.tableize.gsub(/\//, "_")

  has_many association_name, resourcify_options

  self.resource_adapter = Rbacfull::Adapter::Base.create("resource_adapter", self.role_cname, self.name)
  @@resource_types << self.name
end

#role_classObject



60
61
62
63
# File 'lib/rbacfull.rb', line 60

def role_class
  return self.superclass.role_class unless self.instance_variable_defined? '@role_cname'
  self.role_cname.constantize
end

#scopifyObject



55
56
57
58
# File 'lib/rbacfull.rb', line 55

def scopify
  require "rbacfull/adapters/#{Rbacfull.orm}/scopes.rb"
  extend Rbacfull::Adapter::Scopes
end