module Typhoid::Attributes::ClassMethods
Public Instance Methods
auto_init_fields()
click to toggle source
# File lib/typhoid/attributes.rb, line 52 def auto_init_fields @auto_init_fields || [] end
build(klass, response)
click to toggle source
# File lib/typhoid/attributes.rb, line 64 def build(klass, response) builder.call(klass, response) end
builder()
click to toggle source
# File lib/typhoid/attributes.rb, line 56 def builder Builder end
field(*field_names)
click to toggle source
# File lib/typhoid/attributes.rb, line 33 def field(*field_names) raise ArgumentError, "Must specify at least one field" if field_names.length == 0 @auto_init_fields ||= [] field_names.each do |field_name| define_accessor field_name @auto_init_fields << field_name.to_sym end end
load_values(object, response)
click to toggle source
# File lib/typhoid/attributes.rb, line 68 def load_values(object, response) object.tap { |obj| error = nil begin obj.load_values(parser.call response.body) rescue ReadError => e error = e ensure obj.after_build response, error end } end
parser()
click to toggle source
# File lib/typhoid/attributes.rb, line 60 def parser Parser end
Private Instance Methods
define_accessor(field_name)
click to toggle source
# File lib/typhoid/attributes.rb, line 42 def define_accessor(field_name) define_method field_name do attributes[field_name.to_s] end define_method "#{field_name}=" do |new_value| attributes[field_name.to_s] = new_value end end