Class: AccessGranted::Permission
- Inherits:
-
Object
- Object
- AccessGranted::Permission
- Defined in:
- lib/access-granted/permission.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#granted ⇒ Object
readonly
Returns the value of attribute granted.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(granted, action, subject, conditions = {}, block = nil) ⇒ Permission
constructor
A new instance of Permission.
- #matches_action?(action) ⇒ Boolean
- #matches_conditions?(subject) ⇒ Boolean
- #matches_hash_conditions?(subject) ⇒ Boolean
- #matches_subject?(subject) ⇒ Boolean
Constructor Details
#initialize(granted, action, subject, conditions = {}, block = nil) ⇒ Permission
5 6 7 8 9 10 11 |
# File 'lib/access-granted/permission.rb', line 5 def initialize(granted, action, subject, conditions = {}, block = nil) @action = action @granted = granted @subject = subject @conditions = conditions @block = block end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/access-granted/permission.rb', line 3 def action @action end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
3 4 5 |
# File 'lib/access-granted/permission.rb', line 3 def conditions @conditions end |
#granted ⇒ Object (readonly)
Returns the value of attribute granted.
3 4 5 |
# File 'lib/access-granted/permission.rb', line 3 def granted @granted end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/access-granted/permission.rb', line 3 def subject @subject end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/access-granted/permission.rb', line 43 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/access-granted/permission.rb', line 36 def eql?(other) other.class == self.class && @action == other.action && @subject == other.subject && @granted == other.granted end |
#matches_action?(action) ⇒ Boolean
13 14 15 |
# File 'lib/access-granted/permission.rb', line 13 def matches_action?(action) @action == action end |
#matches_conditions?(subject) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/access-granted/permission.rb', line 21 def matches_conditions?(subject) if @block @block.call(subject) else matches_hash_conditions?(subject) end end |
#matches_hash_conditions?(subject) ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/access-granted/permission.rb', line 29 def matches_hash_conditions?(subject) @conditions.each_pair do |name, value| return false if subject.send(name) != value end true end |
#matches_subject?(subject) ⇒ Boolean
17 18 19 |
# File 'lib/access-granted/permission.rb', line 17 def matches_subject?(subject) subject == @subject || subject.class <= @subject end |