Class: Hubbado::Policy::Base
- Inherits:
-
Object
- Object
- Hubbado::Policy::Base
- Includes:
- PolicyDSL
- Defined in:
- lib/hubbado/policy/base.rb
Defined Under Namespace
Modules: PolicyDSL
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
- .build(user, record) ⇒ Object
- .denied(reason = nil, data: nil, i18n_scope: nil) ⇒ Object
- .i18n_scope ⇒ Object
- .permitted ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #denied(reason = nil, data: nil, i18n_scope: nil) ⇒ Object
-
#initialize(user, record) ⇒ Base
constructor
A new instance of Base.
- #permitted ⇒ Object
Methods included from PolicyDSL
Constructor Details
#initialize(user, record) ⇒ Base
Returns a new instance of Base.
65 66 67 68 69 70 |
# File 'lib/hubbado/policy/base.rb', line 65 def initialize(user, record) raise "User not provided" unless user @user = user @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
40 41 42 |
# File 'lib/hubbado/policy/base.rb', line 40 def record @record end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
40 41 42 |
# File 'lib/hubbado/policy/base.rb', line 40 def user @user end |
Class Method Details
.build(user, record) ⇒ Object
42 43 44 45 46 |
# File 'lib/hubbado/policy/base.rb', line 42 def self.build(user, record) instance = new(user, record) instance.configure instance end |
.denied(reason = nil, data: nil, i18n_scope: nil) ⇒ Object
51 52 53 54 55 |
# File 'lib/hubbado/policy/base.rb', line 51 def self.denied(reason = nil, data: nil, i18n_scope: nil) i18n_scope ||= self.i18n_scope reason ||= :denied Result.new(false, reason, i18n_scope: i18n_scope, data: data) end |
.i18n_scope ⇒ Object
61 62 63 |
# File 'lib/hubbado/policy/base.rb', line 61 def self.i18n_scope @i18n_scope ||= Casing::Underscore::String.(name).gsub('/', '.') end |
.permitted ⇒ Object
57 58 59 |
# File 'lib/hubbado/policy/base.rb', line 57 def self.permitted Result.new(true, :permitted) end |
Instance Method Details
#==(other) ⇒ Object
72 73 74 |
# File 'lib/hubbado/policy/base.rb', line 72 def ==(other) self.class == other.class && user == other.user && record == other.record end |
#denied(reason = nil, data: nil, i18n_scope: nil) ⇒ Object
76 77 78 |
# File 'lib/hubbado/policy/base.rb', line 76 def denied(reason = nil, data: nil, i18n_scope: nil) self.class.denied(reason, data: data, i18n_scope: i18n_scope) end |
#permitted ⇒ Object
80 81 82 |
# File 'lib/hubbado/policy/base.rb', line 80 def permitted self.class.permitted end |