Class: Conduit::Core::Parser

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/conduit/core/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attribute(attr_name, &block) ⇒ Object

Define an attribute that will be publically exposed when dealing with conduit responses.



22
23
24
25
# File 'lib/conduit/core/parser.rb', line 22

def attribute(attr_name, &block)
  attributes << attr_name
  define_method(attr_name, &block)
end

.attributesObject

Storage array for all attributes



29
30
31
# File 'lib/conduit/core/parser.rb', line 29

def attributes
  @attributes ||= Set.new
end

Instance Method Details

#response_errorsObject

Default response error container. Should be overwritten by parser implementation.

Raises:

  • (NoMethodError)


56
57
58
# File 'lib/conduit/core/parser.rb', line 56

def response_errors
  raise NoMethodError, 'Please define response_errors in your parser.'
end

#response_statusObject

Default response status. Should be overwritten by parser implementation.

Raises:

  • (NoMethodError)


49
50
51
# File 'lib/conduit/core/parser.rb', line 49

def response_status
  raise NoMethodError, 'Please define response_status in your parser.'
end

#serializable_hashObject

Returns a hash representation of each attribute defined in a parser and its value.



40
41
42
43
44
# File 'lib/conduit/core/parser.rb', line 40

def serializable_hash
  attributes.inject({}) do |hash, attribute|
    hash.tap { |h| h[attribute] = send(attribute) }
  end
end