class Jackal::Formatter

Payload formatter

Constants

DESTINATION

@return [String, Symbol]

SOURCE

@return [String, Symbol]

Public Class Methods

descendants() click to toggle source

@return [Array<Class>] registered formatters

# File lib/jackal/formatter.rb, line 15
def descendants
  @_descendants ||= []
end
inherited(klass) click to toggle source

Register formatter

# File lib/jackal/formatter.rb, line 10
def inherited(klass)
  Formatter.descendants.push(klass).uniq!
end
new(callback=nil) click to toggle source

Create a new instance

@return [self]

# File lib/jackal/formatter.rb, line 29
def initialize(callback=nil)
  @callback = callback
  [:SOURCE, :DESTINATION].each do |key|
    unless(self.class.const_get(key))
      raise NotImplementedError.new("Formatter class must define #{key} constant")
    end
  end
end

Public Instance Methods

destination() click to toggle source

@return [Symbol]

# File lib/jackal/formatter.rb, line 54
def destination
  self.class.const_get(:DESTINATION).to_sym
end
format(payload) click to toggle source

Apply format to payload

@param payload [Smash] @return payload [Smash]

# File lib/jackal/formatter.rb, line 62
def format(payload)
  raise NotImplementedError
end
method_missing(m_name, *args, &block) click to toggle source

Provide a simple proxy out to originating callback if provided to access helpers

Calls superclass method
# File lib/jackal/formatter.rb, line 40
def method_missing(m_name, *args, &block)
  if(@callback && @callback.respond_to?(m_name))
    @callback.send(m_name, *args, &block)
  else
    super
  end
end
source() click to toggle source

@return [Symbol]

# File lib/jackal/formatter.rb, line 49
def source
  self.class.const_get(:SOURCE).to_sym
end