Class: J2119::AllowedFields
- Inherits:
-
Object
- Object
- J2119::AllowedFields
- Defined in:
- lib/j2119/allowed_fields.rb
Instance Method Summary collapse
- #allowed?(roles, child) ⇒ Boolean
- #any?(roles) ⇒ Boolean
-
#initialize ⇒ AllowedFields
constructor
A new instance of AllowedFields.
- #set_allowed(role, child) ⇒ Object
- #set_any(role) ⇒ Object
Constructor Details
#initialize ⇒ AllowedFields
Returns a new instance of AllowedFields.
20 21 22 23 |
# File 'lib/j2119/allowed_fields.rb', line 20 def initialize @allowed = {} @any = [] end |
Instance Method Details
#allowed?(roles, child) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/j2119/allowed_fields.rb', line 34 def allowed?(roles, child) any?(roles) || roles.any? do |role| @allowed[role] && @allowed[role].include?(child) end end |
#any?(roles) ⇒ Boolean
40 41 42 43 44 |
# File 'lib/j2119/allowed_fields.rb', line 40 def any?(roles) roles.any? do |role| @any.include?(role) end end |
#set_allowed(role, child) ⇒ Object
25 26 27 28 |
# File 'lib/j2119/allowed_fields.rb', line 25 def set_allowed(role, child) @allowed[role] ||= [] @allowed[role] << child end |
#set_any(role) ⇒ Object
30 31 32 |
# File 'lib/j2119/allowed_fields.rb', line 30 def set_any(role) @any << role end |