module Xeroizer::Record::ModelDefinitionHelper::ClassMethods

Public Instance Methods

boolean(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 40
def boolean(field_name, options = {});    define_simple_attribute(field_name, :boolean, options); end
date(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 43
def date(field_name, options = {});       define_simple_attribute(field_name, :date, options); end
datetime(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 44
def datetime(field_name, options = {});   define_simple_attribute(field_name, :datetime, options); end
datetime_utc(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 45
def datetime_utc(field_name, options = {});   define_simple_attribute(field_name, :datetime_utc, options); end
decimal(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 42
def decimal(field_name, options = {});    define_simple_attribute(field_name, :decimal, options, 0.0); end
define_simple_attribute(field_name, field_type, options, value_if_nil = nil) click to toggle source

Helper method to simplify field definition. Creates an accessor and reader for the field. Options:

:internal_name => allows the specification of an internal field name differing from the API's field name.
:api_name => allows the API name to be specified if it can't be properly converted from camelize.
:model_name => allows class used for children to be different from it's ndoe name in the XML.
:type => type of field
:skip_writer => skip the writer method
# File lib/xeroizer/record/model_definition_helper.rb, line 61
def define_simple_attribute(field_name, field_type, options, value_if_nil = nil)
  self.fields ||= {}
  
  internal_field_name = options[:internal_name] || field_name
  self.fields[field_name] = options.merge({
    :internal_name  => internal_field_name, 
    :api_name       => options[:api_name] || field_name.to_s.camelize,
    :type           => field_type
  })
  define_method internal_field_name do 
    @attributes[field_name].nil? ? value_if_nil : @attributes[field_name]
  end
  
  unless options[:skip_writer]
    define_method "#{internal_field_name}=".to_sym do | value | 
      parent.mark_dirty(self) if parent
      @attributes[field_name] = value
    end
  end
end
guid(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 47
def guid(field_name, options = {})
  # Ensure all automated Id conversions are changed to ID.
  options[:api_name] ||= field_name.to_s.camelize.gsub(/Id/, 'ID')
  define_simple_attribute(field_name, :guid, options)
end
integer(field_name, options = {}) click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 41
def integer(field_name, options = {});    define_simple_attribute(field_name, :integer, options, 0); end
list_contains_summary_only(status) click to toggle source

Whether this record type's list results contain summary data only.

Records like invoices, when returning a list, only show summary data for certain types of associations (like the contact record) and do not return any data for line items.

Default: false

# File lib/xeroizer/record/model_definition_helper.rb, line 30
def list_contains_summary_only(status)
  self.summary_only = status
end
list_contains_summary_only?() click to toggle source
# File lib/xeroizer/record/model_definition_helper.rb, line 34
def list_contains_summary_only?
  !!summary_only
end
set_possible_primary_keys(*args) click to toggle source

Possible primary keys. At least one of these must exist before attempting to update a record.

# File lib/xeroizer/record/model_definition_helper.rb, line 13
def set_possible_primary_keys(*args)
  args = [args] unless args.is_a?(Array)
  self.possible_primary_keys = args
end
set_primary_key(primary_key_name) click to toggle source

Set the actual Xero primary key for this record.

# File lib/xeroizer/record/model_definition_helper.rb, line 19
def set_primary_key(primary_key_name)
  self.primary_key_name = primary_key_name
end
string(field_name, options = {}) click to toggle source

Helper methods used to define the fields this model has.

# File lib/xeroizer/record/model_definition_helper.rb, line 39
def string(field_name, options = {});     define_simple_attribute(field_name, :string, options); end