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, user = nil, 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, user = nil, conditions = {}, block = nil) ⇒ Permission
Returns a new instance of Permission.
5 6 7 8 9 10 11 12 |
# File 'lib/access-granted/permission.rb', line 5 def initialize(granted, action, subject, user = nil, conditions = {}, block = nil) @action = action @user = user @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
44 45 46 |
# File 'lib/access-granted/permission.rb', line 44 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/access-granted/permission.rb', line 37 def eql?(other) other.class == self.class && @action == other.action && @subject == other.subject && @granted == other.granted end |
#matches_action?(action) ⇒ Boolean
14 15 16 |
# File 'lib/access-granted/permission.rb', line 14 def matches_action?(action) @action == action end |
#matches_conditions?(subject) ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/access-granted/permission.rb', line 22 def matches_conditions?(subject) if @block && !subject.is_a?(Class) @block.call(subject, @user) else matches_hash_conditions?(subject) end end |
#matches_hash_conditions?(subject) ⇒ Boolean
30 31 32 33 34 35 |
# File 'lib/access-granted/permission.rb', line 30 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
18 19 20 |
# File 'lib/access-granted/permission.rb', line 18 def matches_subject?(subject) subject == @subject || subject.class <= @subject end |