Class: Hubbado::Policy::Result
- Inherits:
-
Object
- Object
- Hubbado::Policy::Result
- Defined in:
- lib/hubbado/policy/result.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #denied? ⇒ Boolean
- #generic_deny? ⇒ Boolean
-
#initialize(permitted, reason, i18n_scope: nil, data: nil) ⇒ Result
constructor
A new instance of Result.
- #message ⇒ Object
- #permitted? ⇒ Boolean
Constructor Details
#initialize(permitted, reason, i18n_scope: nil, data: nil) ⇒ Result
Returns a new instance of Result.
7 8 9 10 11 12 13 14 15 |
# File 'lib/hubbado/policy/result.rb', line 7 def initialize(permitted, reason, i18n_scope: nil, data: nil) data ||= {} i18n_scope ||= "hubbado_policy" @permitted = permitted @reason = reason @i18n_scope = i18n_scope @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/hubbado/policy/result.rb', line 5 def data @data end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
4 5 6 |
# File 'lib/hubbado/policy/result.rb', line 4 def reason @reason end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 |
# File 'lib/hubbado/policy/result.rb', line 35 def ==(other) self.class == other.class && permitted? == other.permitted? && @reason == other.reason end |
#denied? ⇒ Boolean
21 22 23 |
# File 'lib/hubbado/policy/result.rb', line 21 def denied? !@permitted end |
#generic_deny? ⇒ Boolean
25 26 27 |
# File 'lib/hubbado/policy/result.rb', line 25 def generic_deny? @reason == :denied end |
#message ⇒ Object
29 30 31 32 33 |
# File 'lib/hubbado/policy/result.rb', line 29 def return if permitted? return ::I18n.t('hubbado_policy.errors.denied') if generic_deny? ::I18n.t(@reason, scope: @i18n_scope) end |
#permitted? ⇒ Boolean
17 18 19 |
# File 'lib/hubbado/policy/result.rb', line 17 def permitted? !!@permitted end |