module Gillbus::Fields
Gives a bunch of class methods to parse gillbus responses hash and define accessors
Warning:
resulting definitions won't work properly in subclass
Usage:
class MyClass extend Gillbus::Fields field :foo, :date end MyClass.parse(hash)
Public Instance Methods
parse(doc, instance: new, parent: nil, options: {})
click to toggle source
# File lib/gillbus/helpers/fields.rb, line 24 def parse(doc, instance: new, parent: nil, options: {}) instance ||= new parser_class.new( doc: doc, instance: instance, fields: field_definitions, parent: parent, options: options, ).parse instance end
parser(&definition)
click to toggle source
# File lib/gillbus/helpers/fields.rb, line 36 def parser(&definition) @parser_class = Class.new(parser_class, &definition) end
parser_class()
click to toggle source
# File lib/gillbus/helpers/fields.rb, line 16 def parser_class if defined? @parser_class @parser_class || Gillbus::Parser else Gillbus::Parser end end
Private Instance Methods
field(name, type = :string, key: name.to_s.upcase, root: nil)
click to toggle source
# File lib/gillbus/helpers/fields.rb, line 46 def field(name, type = :string, key: name.to_s.upcase, root: nil) field_definitions << { name: name, key: key, type: type, root: root } attr_accessor name end
field_definitions()
click to toggle source
# File lib/gillbus/helpers/fields.rb, line 42 def field_definitions @fields ||= [] end