Class: Hippo::Access::LockedFields
- Inherits:
-
Object
- Object
- Hippo::Access::LockedFields
- Defined in:
- lib/hippo/access/locked_fields.rb
Class Method Summary collapse
- .definitions ⇒ Object
-
.lock(klass, field, role, only = nil) ⇒ Object
Lock a given class and attribute to a given role.
-
.roles_needed_for(klass, attribute, access_type) ⇒ Array<Role>
An empty array indicates that the field is not locked and the Model should be used for determining access.
Class Method Details
.definitions ⇒ Object
35 36 37 |
# File 'lib/hippo/access/locked_fields.rb', line 35 def definitions @definitions end |
.lock(klass, field, role, only = nil) ⇒ Object
Lock a given class and attribute to a given role
31 32 33 |
# File 'lib/hippo/access/locked_fields.rb', line 31 def lock(klass, field, role, only=nil) @definitions[klass][field] << { role: role, only: only } end |
.roles_needed_for(klass, attribute, access_type) ⇒ Array<Role>
An empty array indicates that the field is not locked and the Model should be used for determining access
17 18 19 20 21 22 23 24 25 |
# File 'lib/hippo/access/locked_fields.rb', line 17 def roles_needed_for(klass, attribute, access_type) if @definitions.has_key?(klass) && @definitions[klass].has_key?(attribute) @definitions[klass][attribute].each_with_object([]) do | grant, result | result.push(grant[:role]) if grant[:only].nil? || grant[:only] == access_type end else [] end end |