Module: Xeroizer::Record::ModelDefinitionHelper::ClassMethods
- Defined in:
- lib/xeroizer/record/model_definition_helper.rb
Instance Method Summary collapse
- #boolean(field_name, options = {}) ⇒ Object
- #date(field_name, options = {}) ⇒ Object
- #datetime(field_name, options = {}) ⇒ Object
- #datetime_utc(field_name, options = {}) ⇒ Object
- #decimal(field_name, options = {}) ⇒ Object
-
#define_simple_attribute(field_name, field_type, options, value_if_nil = nil) ⇒ Object
Helper method to simplify field definition.
- #guid(field_name, options = {}) ⇒ Object
- #integer(field_name, options = {}) ⇒ Object
-
#list_contains_summary_only(status) ⇒ Object
Whether this record type’s list results contain summary data only.
- #list_contains_summary_only? ⇒ Boolean
-
#set_possible_primary_keys(*args) ⇒ Object
Possible primary keys.
-
#set_primary_key(primary_key_name) ⇒ Object
Set the actual Xero primary key for this record.
-
#string(field_name, options = {}) ⇒ Object
Helper methods used to define the fields this model has.
Instance Method Details
#boolean(field_name, options = {}) ⇒ Object
40 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 40 def boolean(field_name, = {}); define_simple_attribute(field_name, :boolean, ); end |
#date(field_name, options = {}) ⇒ Object
43 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 43 def date(field_name, = {}); define_simple_attribute(field_name, :date, ); end |
#datetime(field_name, options = {}) ⇒ Object
44 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 44 def datetime(field_name, = {}); define_simple_attribute(field_name, :datetime, ); end |
#datetime_utc(field_name, options = {}) ⇒ Object
45 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 45 def datetime_utc(field_name, = {}); define_simple_attribute(field_name, :datetime_utc, ); end |
#decimal(field_name, options = {}) ⇒ Object
42 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 42 def decimal(field_name, = {}); define_simple_attribute(field_name, :decimal, , 0.0); end |
#define_simple_attribute(field_name, field_type, options, value_if_nil = nil) ⇒ Object
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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 61 def define_simple_attribute(field_name, field_type, , value_if_nil = nil) self.fields ||= {} internal_field_name = [:internal_name] || field_name self.fields[field_name] = .merge({ :internal_name => internal_field_name, :api_name => [:api_name] || field_name.to_s.camelize, :type => field_type }) define_method internal_field_name do @attributes[field_name] || value_if_nil end unless [: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 = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 47 def guid(field_name, = {}) # Ensure all automated Id conversions are changed to ID. [:api_name] ||= field_name.to_s.camelize.gsub(/Id/, 'ID') define_simple_attribute(field_name, :guid, ) end |
#integer(field_name, options = {}) ⇒ Object
41 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 41 def integer(field_name, = {}); define_simple_attribute(field_name, :integer, , 0); end |
#list_contains_summary_only(status) ⇒ Object
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
30 31 32 |
# 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? ⇒ Boolean
34 35 36 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 34 def list_contains_summary_only? !!summary_only end |
#set_possible_primary_keys(*args) ⇒ Object
Possible primary keys. At least one of these must exist before attempting to update a record.
13 14 15 16 |
# 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) ⇒ Object
Set the actual Xero primary key for this record.
19 20 21 |
# 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 = {}) ⇒ Object
Helper methods used to define the fields this model has.
39 |
# File 'lib/xeroizer/record/model_definition_helper.rb', line 39 def string(field_name, = {}); define_simple_attribute(field_name, :string, ); end |