Module: Rolify
- Extended by:
- Configure
- Defined in:
- lib/rolify.rb,
lib/rolify/role.rb,
lib/rolify/utils.rb,
lib/rolify/dynamic.rb,
lib/rolify/finders.rb,
lib/rolify/railtie.rb,
lib/rolify/version.rb,
lib/rolify/resource.rb,
lib/rolify/configure.rb,
lib/rolify/adapters/base.rb,
lib/rolify/adapters/mongoid/scopes.rb,
lib/generators/rolify/user_generator.rb,
lib/generators/rolify/rolify_generator.rb,
lib/rolify/adapters/active_record/scopes.rb,
lib/rolify/adapters/mongoid/role_adapter.rb,
lib/rolify/adapters/mongoid/resource_adapter.rb,
lib/rolify/adapters/active_record/role_adapter.rb,
lib/rolify/adapters/active_record/resource_adapter.rb
Defined Under Namespace
Modules: Adapter, Configure, Dynamic, Finders, Generators, Resource, Role, Utils Classes: Railtie
Constant Summary collapse
- VERSION =
"6.0.1"
- @@resource_types =
[]
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#resource_adapter ⇒ Object
Returns the value of attribute resource_adapter.
-
#role_cname ⇒ Object
Returns the value of attribute role_cname.
-
#role_join_table_name ⇒ Object
Returns the value of attribute role_join_table_name.
-
#role_table_name ⇒ Object
Returns the value of attribute role_table_name.
-
#strict_rolify ⇒ Object
Returns the value of attribute strict_rolify.
Class Method Summary collapse
Instance Method Summary collapse
- #resourcify(association_name = :roles, options = {}) ⇒ Object
- #role_class ⇒ Object
- #rolify(options = {}) ⇒ Object
- #scopify ⇒ Object
Methods included from Configure
configure, dynamic_shortcuts, dynamic_shortcuts=, orm, orm=, remove_role_if_empty, remove_role_if_empty=, use_defaults, use_dynamic_shortcuts, use_mongoid
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/rolify.rb', line 11 def adapter @adapter end |
#resource_adapter ⇒ Object
Returns the value of attribute resource_adapter.
11 12 13 |
# File 'lib/rolify.rb', line 11 def resource_adapter @resource_adapter end |
#role_cname ⇒ Object
Returns the value of attribute role_cname.
11 12 13 |
# File 'lib/rolify.rb', line 11 def role_cname @role_cname end |
#role_join_table_name ⇒ Object
Returns the value of attribute role_join_table_name.
11 12 13 |
# File 'lib/rolify.rb', line 11 def role_join_table_name @role_join_table_name end |
#role_table_name ⇒ Object
Returns the value of attribute role_table_name.
11 12 13 |
# File 'lib/rolify.rb', line 11 def role_table_name @role_table_name end |
#strict_rolify ⇒ Object
Returns the value of attribute strict_rolify.
11 12 13 |
# File 'lib/rolify.rb', line 11 def strict_rolify @strict_rolify end |
Class Method Details
.resource_types ⇒ Object
72 73 74 |
# File 'lib/rolify.rb', line 72 def self.resource_types @@resource_types end |
Instance Method Details
#resourcify(association_name = :roles, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rolify.rb', line 43 def resourcify(association_name = :roles, = {}) include Resource .reverse_merge!({ :role_cname => 'Role', :dependent => :destroy }) = { :class_name => [:role_cname].camelize, :as => :resource, :dependent => [:dependent] } self.role_cname = [:role_cname] self.role_table_name = self.role_cname.tableize.gsub(/\//, "_") has_many association_name, ** self.resource_adapter = Rolify::Adapter::Base.create("resource_adapter", self.role_cname, self.name) @@resource_types << self.name end |
#role_class ⇒ Object
67 68 69 70 |
# File 'lib/rolify.rb', line 67 def role_class return self.superclass.role_class unless self.instance_variable_defined? '@role_cname' self.role_cname.constantize end |
#rolify(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rolify.rb', line 14 def rolify( = {}) include Role extend Dynamic if Rolify.dynamic_shortcuts .reverse_merge!({:role_cname => 'Role'}) self.role_cname = [:role_cname] self.role_table_name = self.role_cname.tableize.gsub(/\//, "_") default_join_table = "#{self.to_s.tableize.gsub(/\//, "_")}_#{self.role_table_name}" .reverse_merge!({:role_join_table_name => default_join_table}) self.role_join_table_name = [:role_join_table_name] = { :class_name => [:role_cname].camelize } .merge!({ :join_table => self.role_join_table_name }) if Rolify.orm == "active_record" .merge!(.reject{ |k,v| ![ :before_add, :after_add, :before_remove, :after_remove, :inverse_of ].include? k.to_sym }) has_and_belongs_to_many :roles, ** self.adapter = Rolify::Adapter::Base.create("role_adapter", self.role_cname, self.name) #use strict roles self.strict_rolify = true if [:strict] end |