Class: ViewModel::AccessControl::Composed::ComposedResult
- Inherits:
-
Struct
- Object
- Struct
- ViewModel::AccessControl::Composed::ComposedResult
- Defined in:
- lib/view_model/access_control/composed.rb
Instance Attribute Summary collapse
-
#allow ⇒ Object
Returns the value of attribute allow.
-
#allow_error ⇒ Object
Returns the value of attribute allow_error.
-
#veto ⇒ Object
Returns the value of attribute veto.
-
#veto_error ⇒ Object
Returns the value of attribute veto_error.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(allow, veto, allow_error, veto_error) ⇒ ComposedResult
constructor
A new instance of ComposedResult.
-
#merge(&_block) ⇒ Object
Merge this composed result with another.
- #permit? ⇒ Boolean
Constructor Details
#initialize(allow, veto, allow_error, veto_error) ⇒ ComposedResult
Returns a new instance of ComposedResult.
10 11 12 13 14 15 |
# File 'lib/view_model/access_control/composed.rb', line 10 def initialize(allow, veto, allow_error, veto_error) raise ArgumentError.new('Non-vetoing result may not have a veto error') if veto_error && !veto raise ArgumentError.new('Allowing result may not have a allow error') if allow_error && allow super end |
Instance Attribute Details
#allow ⇒ Object
Returns the value of attribute allow
9 10 11 |
# File 'lib/view_model/access_control/composed.rb', line 9 def allow @allow end |
#allow_error ⇒ Object
Returns the value of attribute allow_error
9 10 11 |
# File 'lib/view_model/access_control/composed.rb', line 9 def allow_error @allow_error end |
#veto ⇒ Object
Returns the value of attribute veto
9 10 11 |
# File 'lib/view_model/access_control/composed.rb', line 9 def veto @veto end |
#veto_error ⇒ Object
Returns the value of attribute veto_error
9 10 11 |
# File 'lib/view_model/access_control/composed.rb', line 9 def veto_error @veto_error end |
Instance Method Details
#error ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/view_model/access_control/composed.rb', line 21 def error case when veto then veto_error when !allow then allow_error else nil end end |
#merge(&_block) ⇒ Object
Merge this composed result with another. ‘allow`s widen and `veto`es narrow.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/view_model/access_control/composed.rb', line 30 def merge(&_block) if self.veto self else other = yield new_allow = self.allow || other.allow new_allow_error = case when new_allow nil when self.allow_error.nil? other.allow_error when other.allow_error.nil? self.allow_error # Mergeable (standard) errors should be merged if possible; if not # possible, we should take the first non-standard error. when mergeable_error?(self.allow_error) if mergeable_error?(other.allow_error) self.allow_error.merge(other.allow_error) else other.allow_error end else self.allow_error end ComposedResult.new(new_allow, other.veto, new_allow_error, other.veto_error) end end |
#permit? ⇒ Boolean
17 18 19 |
# File 'lib/view_model/access_control/composed.rb', line 17 def permit? !veto && allow end |