module ActiveZuora::Fields

Public Class Methods

new(attributes={}) click to toggle source
# File lib/active_zuora/fields.rb, line 22
def initialize(attributes={})
  # Start with defaults, and override those with the given attributes.
  self.attributes = default_attributes.merge(attributes)
end

Public Instance Methods

attributes() click to toggle source
# File lib/active_zuora/fields.rb, line 27
def attributes
  # A requirement of ActiveModel::Attributes.
  # Hash must use string keys.
  attributes = {}
  fields.each { |field| attributes[field.name] = send(field.name) }
  attributes
end
attributes=(attributes) click to toggle source
# File lib/active_zuora/fields.rb, line 35
def attributes=(attributes)
  attributes.each { |key, value| send("#{key}=", value) }
end
clear_changed_attributes() click to toggle source
# File lib/active_zuora/fields.rb, line 54
def clear_changed_attributes
  if ActiveSupport.version.to_s.to_f >= 5.2
    clear_changes_information
  else
    changed_attributes.clear
  end

  # If we have any fields that are also Base objects,
  # clear their attributes as well.
  fields.each { |field| field.clear_changed_attributes(send(field.name)) }
end
untracked_attributes=(attributes) click to toggle source
# File lib/active_zuora/fields.rb, line 39
def untracked_attributes=(attributes)
  # Loads attributes without tracking dirt.
  self.attributes = attributes
  clear_changed_attributes
  attributes
end
write_attribute(name, value) click to toggle source
# File lib/active_zuora/fields.rb, line 46
def write_attribute(name, value)
  field = get_field!(name)
  value = field.type_cast(value)
  attribute_will_change!(name) if value != send(name)
  instance_variable_set("@#{name}", value)
  value
end