Class: Xeroizer::Record::Base
- Inherits:
-
Object
- Object
- Xeroizer::Record::Base
- Includes:
- ClassLevelInheritableAttributes, ModelDefinitionHelper, RecordAssociationHelper, ValidationHelper, XmlHelper
- Defined in:
- lib/xeroizer/record/base.rb
Direct Known Subclasses
Account, Address, BankAccount, BankTransaction, BrandingTheme, Contact, ContactGroup, CreditNote, Currency, Employee, ExternalLink, Invoice, Item, ItemPurchaseDetails, ItemSalesDetails, Journal, JournalLine, JournalLineTrackingCategory, LineItem, ManualJournal, ManualJournalLine, Option, Organisation, Payment, Phone, TaxRate, TrackingCategory, TrackingCategoryChild
Instance Attribute Summary (collapse)
-
- (Object) attributes
Returns the value of attribute attributes.
-
- (Object) complete_record_downloaded
Returns the value of attribute complete_record_downloaded.
-
- (Object) errors
Returns the value of attribute errors.
-
- (Object) parent
readonly
Returns the value of attribute parent.
Class Method Summary (collapse)
-
+ (Object) build(attributes, parent)
Build a record with attributes set to the value of attributes.
Instance Method Summary (collapse)
- - (Object) [](attribute)
- - (Object) []=(attribute, value)
-
- (Object) as_json(options = {})
Deprecated.
-
- (Boolean) complete_record_downloaded?
Check to see if the complete record is downloaded.
-
- (Object) download_complete_record!
Downloads the complete record if we only have a summary of the record.
-
- (Base) initialize(parent)
constructor
A new instance of Base.
- - (Object) inspect
- - (Object) new_model_class(model_name)
- - (Boolean) new_record?
- - (Object) save
- - (Object) saved!
- - (Object) to_h
- - (Object) to_json(*args)
- - (Object) update_attributes(attributes)
Methods included from XmlHelper
Methods included from ValidationHelper
Methods included from RecordAssociationHelper
Methods included from ModelDefinitionHelper
Methods included from ClassLevelInheritableAttributes
Constructor Details
- (Base) initialize(parent)
A new instance of Base
40 41 42 43 |
# File 'lib/xeroizer/record/base.rb', line 40 def initialize(parent) @parent = parent @attributes = {} end |
Instance Attribute Details
- (Object) attributes
Returns the value of attribute attributes
15 16 17 |
# File 'lib/xeroizer/record/base.rb', line 15 def attributes @attributes end |
- (Object) complete_record_downloaded
Returns the value of attribute complete_record_downloaded
18 19 20 |
# File 'lib/xeroizer/record/base.rb', line 18 def complete_record_downloaded @complete_record_downloaded end |
- (Object) errors
Returns the value of attribute errors
17 18 19 |
# File 'lib/xeroizer/record/base.rb', line 17 def errors @errors end |
- (Object) parent (readonly)
Returns the value of attribute parent
16 17 18 |
# File 'lib/xeroizer/record/base.rb', line 16 def parent @parent end |
Class Method Details
+ (Object) build(attributes, parent)
Build a record with attributes set to the value of attributes.
28 29 30 31 32 33 34 |
# File 'lib/xeroizer/record/base.rb', line 28 def build(attributes, parent) record = new(parent) attributes.each do | key, value | record.send("#{key}=".to_sym, value) end record end |
Instance Method Details
- (Object) [](attribute)
49 50 51 |
# File 'lib/xeroizer/record/base.rb', line 49 def [](attribute) self.send(attribute) end |
- (Object) []=(attribute, value)
53 54 55 56 |
# File 'lib/xeroizer/record/base.rb', line 53 def []=(attribute, value) parent.mark_dirty(self) if parent self.send("#{attribute}=".to_sym, value) end |
- (Object) as_json(options = {})
Deprecated
114 115 116 |
# File 'lib/xeroizer/record/base.rb', line 114 def as_json( = {}) to_h.to_json end |
- (Boolean) complete_record_downloaded?
Check to see if the complete record is downloaded.
76 77 78 79 80 81 82 |
# File 'lib/xeroizer/record/base.rb', line 76 def complete_record_downloaded? if !!self.class.list_contains_summary_only? !!complete_record_downloaded else true end end |
- (Object) download_complete_record!
Downloads the complete record if we only have a summary of the record.
85 86 87 88 89 90 91 |
# File 'lib/xeroizer/record/base.rb', line 85 def download_complete_record! record = self.parent.find(self.id) @attributes = record.attributes if record @complete_record_downloaded = true parent.mark_clean(self) self end |
- (Object) inspect
125 126 127 128 129 130 |
# File 'lib/xeroizer/record/base.rb', line 125 def inspect attribute_string = self.attributes.collect do |attr, value| "#{attr.inspect}: #{value.inspect}" end.join(", ") "#<#{self.class} #{attribute_string}>" end |
- (Object) new_model_class(model_name)
45 46 47 |
# File 'lib/xeroizer/record/base.rb', line 45 def new_model_class(model_name) Xeroizer::Record.const_get("#{model_name}Model".to_sym).new(parent.application, model_name.to_s) end |
- (Boolean) new_record?
71 72 73 |
# File 'lib/xeroizer/record/base.rb', line 71 def new_record? id.nil? end |
- (Object) save
93 94 95 96 97 98 99 100 101 |
# File 'lib/xeroizer/record/base.rb', line 93 def save return false unless valid? if new_record? create else update end saved! end |
- (Object) saved!
103 104 105 106 107 |
# File 'lib/xeroizer/record/base.rb', line 103 def saved! @complete_record_downloaded = true parent.mark_clean(self) true end |
- (Object) to_h
118 119 120 121 122 123 |
# File 'lib/xeroizer/record/base.rb', line 118 def to_h attrs = self.attributes.reject {|k, v| k == :parent }.map do |k, v| [k, v.kind_of?(Array) ? v.map(&:to_h) : (v.respond_to?(:to_h) ? v.to_h : v)] end Hash[attrs] end |
- (Object) to_json(*args)
109 110 111 |
# File 'lib/xeroizer/record/base.rb', line 109 def to_json(*args) to_h.to_json(*args) end |
- (Object) update_attributes(attributes)
66 67 68 69 |
# File 'lib/xeroizer/record/base.rb', line 66 def update_attributes(attributes) self.attributes = attributes save end |