Module: Railjet::UseCase
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/railjet/use_case.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #check_ability!(*args) ⇒ Object
- #check_policy!(*args) ⇒ Object
- #initialize(context) ⇒ Object
- #with_ability_check(*args) ⇒ Object
- #with_policy_check(*args) ⇒ Object
- #with_requirements_check(*args) ⇒ Object
Methods included from Railjet::Util::PolicyHelper
Methods included from Railjet::Util::UseCaseHelper
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/railjet/use_case.rb', line 7 def context @context end |
Instance Method Details
#check_ability!(*args) ⇒ Object
36 37 38 |
# File 'lib/railjet/use_case.rb', line 36 def check_ability!(*args) true end |
#check_policy!(*args) ⇒ Object
40 41 42 |
# File 'lib/railjet/use_case.rb', line 40 def check_policy!(*args) true end |
#initialize(context) ⇒ Object
9 10 11 |
# File 'lib/railjet/use_case.rb', line 9 def initialize(context) @context = context end |
#with_ability_check(*args) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/railjet/use_case.rb', line 21 def with_ability_check(*args) if check_ability!(*args) yield if block_given? else raise Railjet::UnauthorizedError end end |
#with_policy_check(*args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/railjet/use_case.rb', line 29 def with_policy_check(*args) check_policy!(*args) yield if block_given? rescue Railjet::PolicyError => e raise Railjet::PolicyNotMetError.new(e.errors) end |
#with_requirements_check(*args) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/railjet/use_case.rb', line 13 def with_requirements_check(*args) with_ability_check(*args) do with_policy_check(*args) do yield if block_given? end end end |