module Apiway::Controller::ClassMethods

Public Instance Methods

action( name, &block ) click to toggle source
# 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: [] ) click to toggle source
# 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: [] ) click to toggle source
# 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 ) click to toggle source
# 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

Private Instance Methods

actions() click to toggle source
# File lib/apiway/controller.rb, line 43
def actions
  @actions ||= {}
end
filters( type ) click to toggle source
# File lib/apiway/controller.rb, line 47
def filters( type )
  ( @filters ||= {} )[ type ] ||= []
end
register_filter( type, method_name, only, except ) click to toggle source
# File lib/apiway/controller.rb, line 51
def register_filter( type, method_name, only, except )
  only   = [].push( only ).flatten
  except = [].push( except ).flatten
  filters( type ) << [ method_name, only, except ]
end