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.



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

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

.attributesObject

Storage array for all attributes



27
28
29
# File 'lib/conduit/core/parser.rb', line 27

def attributes
  @attributes ||= Set.new
end

Instance Method Details

#response_errorsObject

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

Raises:

  • (NoMethodError)


54
55
56
# File 'lib/conduit/core/parser.rb', line 54

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)


47
48
49
# File 'lib/conduit/core/parser.rb', line 47

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.



38
39
40
41
42
# File 'lib/conduit/core/parser.rb', line 38

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