class Parxer::Callbacks

Constants

CALLBACK_TYPES

Public Instance Methods

add_callback(type, action, config = {}) click to toggle source
# File lib/parxer/collections/callbacks.rb, line 5
def add_callback(type, action, config = {})
  if !CALLBACK_TYPES.include?(type.to_sym)
    raise Parxer::CallbacksError.new("invalid '#{type}' callback type")
  end

  if !action.is_a?(Proc) && !action.is_a?(Symbol)
    raise Parxer::CallbacksError.new("action param must by a Proc or symbol method name")
  end

  self << Parxer::Callback.new(type: type, action: action, config: config || {})
  last
end
by_type(type) click to toggle source
# File lib/parxer/collections/callbacks.rb, line 18
def by_type(type)
  select { |callback| callback.type == type.to_sym }
end