module PayuZa::Structs::StructModel::ClassMethods

Public Instance Methods

create(attributes) click to toggle source
# 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 = {}) click to toggle source
# 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
fields() click to toggle source
# File lib/payu_za/structs/struct_model.rb, line 83
def fields
  @fields ||= {}
end