Module: Trailblazer::V1_1::Operation::Policy::Guard

Defined in:
lib/trailblazer/1.1/operation/policy/guard.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



9
10
11
12
13
# File 'lib/trailblazer/1.1/operation/policy/guard.rb', line 9

def self.included(includer)
  includer.extend(DSL) # Provides ::policy(CallableObject)
  includer.extend(ClassMethods)
  includer.send(:include, Setup)
end

Instance Method Details

#call_policy(params) ⇒ Object

Override if you want your own policy invocation, e.g. with more args.



26
27
28
# File 'lib/trailblazer/1.1/operation/policy/guard.rb', line 26

def call_policy(params)
  self.class.policy_config.(self, params)
end

#evaluate_policy(params) ⇒ Object



21
22
23
# File 'lib/trailblazer/1.1/operation/policy/guard.rb', line 21

def evaluate_policy(params)
  call_policy(params) or raise policy_exception
end

#policy_exceptionObject



30
31
32
# File 'lib/trailblazer/1.1/operation/policy/guard.rb', line 30

def policy_exception
  NotAuthorizedError.new
end