Module: Guachiman::Permissions
- Included in:
- Permission
- Defined in:
- lib/guachiman/permissions.rb
Instance Attribute Summary collapse
-
#allow_all ⇒ Object
readonly
Returns the value of attribute allow_all.
-
#allowed_actions ⇒ Object
readonly
Returns the value of attribute allowed_actions.
Instance Method Summary collapse
- #allow(controllers, actions, &block) ⇒ Object
- #allow?(controller, action, resource = nil) ⇒ Boolean
- #allow_all! ⇒ Object
Instance Attribute Details
#allow_all ⇒ Object (readonly)
Returns the value of attribute allow_all.
3 4 5 |
# File 'lib/guachiman/permissions.rb', line 3 def allow_all @allow_all end |
#allowed_actions ⇒ Object (readonly)
Returns the value of attribute allowed_actions.
3 4 5 |
# File 'lib/guachiman/permissions.rb', line 3 def allowed_actions @allowed_actions end |
Instance Method Details
#allow(controllers, actions, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/guachiman/permissions.rb', line 5 def allow controllers, actions, &block @allowed_actions ||= {} Array(controllers).each do |controller| Array(actions).each do |action| allowed_actions[controller] ||= {} allowed_actions[controller].merge! action => (block || true) end end end |
#allow?(controller, action, resource = nil) ⇒ Boolean
15 16 17 18 |
# File 'lib/guachiman/permissions.rb', line 15 def allow? controller, action, resource=nil allowed = allow_all || check_allowed_action(controller, action) !!allowed && (allowed == true || resource && allowed.call(resource)) end |
#allow_all! ⇒ Object
20 21 22 |
# File 'lib/guachiman/permissions.rb', line 20 def allow_all! @allow_all = true end |