Class: Conduit::Core::Parser

Inherits:
Object
  • Object
show all
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.



15
16
17
18
# File 'lib/conduit/core/parser.rb', line 15

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

.attributesObject

Storage array for all attributes



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

def attributes
  @attributes ||= []
end

Instance Method Details

#response_errorsObject

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

Raises:

  • (NoMethodError)


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

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)


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

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.



33
34
35
36
37
# File 'lib/conduit/core/parser.rb', line 33

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