Module: Apiway::Controller::ClassMethods

Defined in:
lib/apiway/controller.rb

Instance Method Summary collapse

Instance Method Details

#action(name, &block) ⇒ Object



22
23
24
# File 'lib/apiway/controller.rb', line 22

def action( name, &block )
  block_given? ? actions[ name ] = block : actions[ name ] or raise ControllerActionNotExists.new( self.name, name )
end

#after_action(method_name, only: [], except: []) ⇒ Object



30
31
32
# File 'lib/apiway/controller.rb', line 30

def after_action( method_name, only: [], except: [] )
  register_filter :after, method_name, only, except
end

#before_action(method_name, only: [], except: []) ⇒ Object



26
27
28
# File 'lib/apiway/controller.rb', line 26

def before_action( method_name, only: [], except: [] )
  register_filter :before, method_name, only, except
end

#select_filters(type, action_name) ⇒ Object



34
35
36
37
38
# File 'lib/apiway/controller.rb', line 34

def select_filters( type, action_name )
  filters( type ).select do |method_name, only, except|
    ( only.empty? || only.include?( action_name ) ) && ( except.empty? || !except.include?( action_name ) )
  end
end