Class: Polar::Permissions
- Inherits:
-
Object
- Object
- Polar::Permissions
- Defined in:
- lib/polar/permissions.rb
Instance Attribute Summary collapse
-
#defined_permissions_store ⇒ Object
Returns the value of attribute defined_permissions_store.
-
#permissions_for_controller ⇒ Object
Returns the value of attribute permissions_for_controller.
-
#subject_store ⇒ Object
Returns the value of attribute subject_store.
Class Method Summary collapse
- .add_for_controller(perm_hash) ⇒ Object
- .define(&block) ⇒ Object
- .defined_store ⇒ Object
- .for_controller ⇒ Object
- .instance ⇒ Object
- .method_missing(method) {|PermissionHash.new(method)| ... } ⇒ Object
Instance Method Summary collapse
- #fill_subject_from_external_store(subject_id, perm_storage, group_storage) ⇒ Object
-
#initialize(instance_object = false) ⇒ Permissions
constructor
A new instance of Permissions.
Constructor Details
#initialize(instance_object = false) ⇒ Permissions
Returns a new instance of Permissions.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/polar/permissions.rb', line 23 def initialize(instance_object = false) @defined_permissions_store ||= [] @subject_store ||= [] unless instance_object @defined_permissions_store = self.class.instance..clone @subject_store = self.class.instance.subject_store.clone end self end |
Instance Attribute Details
#defined_permissions_store ⇒ Object
Returns the value of attribute defined_permissions_store.
19 20 21 |
# File 'lib/polar/permissions.rb', line 19 def @defined_permissions_store end |
#permissions_for_controller ⇒ Object
Returns the value of attribute permissions_for_controller.
21 22 23 |
# File 'lib/polar/permissions.rb', line 21 def @permissions_for_controller end |
#subject_store ⇒ Object
Returns the value of attribute subject_store.
20 21 22 |
# File 'lib/polar/permissions.rb', line 20 def subject_store @subject_store end |
Class Method Details
.add_for_controller(perm_hash) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/polar/permissions.rb', line 54 def self.add_for_controller(perm_hash) controller = perm_hash[:object].to_sym actions = perm_hash[:params].present? && perm_hash[:params].has_key?(:only) ? perm_hash[:params][:only] : [:all] for_controller[controller] ||= {} actions.each do |action| for_controller[controller][action] ||= {:allow => [], :deny => []} for_controller[controller][action][perm_hash[:access_type]] << perm_hash[:permission_name] end end |
.define(&block) ⇒ Object
38 39 40 |
# File 'lib/polar/permissions.rb', line 38 def self.define(&block) self end |
.defined_store ⇒ Object
46 47 48 |
# File 'lib/polar/permissions.rb', line 46 def self.defined_store @defined_permissions_store ||= {} end |
.for_controller ⇒ Object
50 51 52 |
# File 'lib/polar/permissions.rb', line 50 def self.for_controller @permissions_for_controller ||= {} end |
.instance ⇒ Object
34 35 36 |
# File 'lib/polar/permissions.rb', line 34 def self.instance @__instance__ ||= new(true) end |
.method_missing(method) {|PermissionHash.new(method)| ... } ⇒ Object
42 43 44 |
# File 'lib/polar/permissions.rb', line 42 def self.method_missing(method, &block) yield PermissionHash.new(method) if block_given? end |
Instance Method Details
#fill_subject_from_external_store(subject_id, perm_storage, group_storage) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/polar/permissions.rb', line 64 def fill_subject_from_external_store(subject_id, perm_storage, group_storage) perm_storage.get_for_subject(subject_id).each do |perm| self.subject_store << perm..to_sym end groups = Polar::Groups.new groups.fill_subject_from_external_store(subject_id, group_storage) groups.subject_store.each do |group| if Polar::Groups.defined_store.has_key?(group.to_sym) self.subject_store.concat(Polar::Groups.defined_store[group.to_sym][:params]) end end end |