Module: PayuZa::Structs::StructModel::ClassMethods

Defined in:
lib/payu_za/structs/struct_model.rb

Instance Method Summary collapse

Instance Method Details

#create(attributes) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/payu_za/structs/struct_model.rb', line 75

def create(attributes)
  new.tap do |struct|
    attributes.each do |name, value|
      struct.send("#{name}=", value)
    end
  end
end

#field(name, options = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/payu_za/structs/struct_model.rb', line 63

def field(name, options = {})
  fields[name] = options

  define_method name do
    instance_variable_get(:"@#{name}") || default_for(name)
  end

  define_method "#{name}=" do |value|
    instance_variable_set(:"@#{name}", value)
  end
end

#fieldsObject



83
84
85
# File 'lib/payu_za/structs/struct_model.rb', line 83

def fields
  @fields ||= {}
end