Class: Sanction::Permission
- Inherits:
-
Object
- Object
- Sanction::Permission
- Defined in:
- lib/sanction/permission.rb
Instance Attribute Summary collapse
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Instance Method Summary collapse
-
#initialize(permission_graph, *predicates) ⇒ Permission
constructor
A new instance of Permission.
- #path ⇒ Object
- #permitted? ⇒ Boolean
- #permitted_with_scope?(scope) ⇒ Boolean
- #persisted? ⇒ Boolean
Constructor Details
#initialize(permission_graph, *predicates) ⇒ Permission
Returns a new instance of Permission.
6 7 8 9 |
# File 'lib/sanction/permission.rb', line 6 def initialize(, *predicates) @graph = @predicates = predicates end |
Instance Attribute Details
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
4 5 6 |
# File 'lib/sanction/permission.rb', line 4 def predicates @predicates end |
Instance Method Details
#path ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sanction/permission.rb', line 11 def path @path ||= begin path = @graph.root @predicates.each do |predicate| if predicate.is_a?(Class) path = path[predicate.to_s.demodulize.underscore.to_sym] else path = path[predicate.class.to_s.demodulize.underscore.to_sym][predicate.id] end end path end end |
#permitted? ⇒ Boolean
29 30 31 |
# File 'lib/sanction/permission.rb', line 29 def permitted? path.permitted? end |
#permitted_with_scope?(scope) ⇒ Boolean
33 34 35 |
# File 'lib/sanction/permission.rb', line 33 def permitted_with_scope?(scope) permitted? && path.has_scope?(scope) end |
#persisted? ⇒ Boolean
25 26 27 |
# File 'lib/sanction/permission.rb', line 25 def persisted? path.persisted? end |