Class: Core::Endpoint::BasicHandler::Actions::Guards::Guard

Inherits:
Object
  • Object
show all
Defined in:
app/api/core/endpoint/basic_handler/actions/guards.rb

Instance Method Summary collapse

Constructor Details

#initialize(method = nil, &block) ⇒ Guard

Returns a new instance of Guard


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/api/core/endpoint/basic_handler/actions/guards.rb', line 3

def initialize(method = nil, &block)
  if method.present?
    line = __LINE__ + 1
    singleton_class.class_eval("
      def execute(object)
        object.#{method}
      end
    ", __FILE__, line)
  elsif block_given?
    singleton_class.send(:define_method, :execute, &block)
  else
    raise StandardError, 'Either method name or block is required for guards'
  end
end