Class: LedgerSync::Resource
Direct Known Subclasses
Account, Bill, BillLineItem, Currency, Customer, Department, Deposit, DepositLineItem, Expense, ExpenseLineItem, Invoice, InvoiceSalesLineItem, Item, JournalEntry, JournalEntryLineItem, LedgerClass, Payment, PaymentLineItem, Subsidiary, Transfer, Vendor
Constant Summary
collapse
- PRIMITIVES =
[
ActiveModel::Type,
Date,
DateTime,
FalseClass,
Float,
Integer,
NilClass,
String,
Time,
TrueClass
].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
included
included
included, #initialize, #resource_attributes, #save, #serialize_attributes
#valid?, #validate, #validate_or_fail
Class Method Details
.inherited(subclass) ⇒ Object
61
62
63
64
|
# File 'lib/ledger_sync/resource.rb', line 61
def self.inherited(subclass)
subclass.attribute :external_id, type: Type::ID
subclass.attribute :ledger_id, type: Type::ID
end
|
.resource_module_str ⇒ Object
66
67
68
|
# File 'lib/ledger_sync/resource.rb', line 66
def self.resource_module_str
@resource_module_str ||= name.split('LedgerSync::')[1..-1].join('LedgerSync::')
end
|
.serialize_attribute?(sattr) ⇒ Boolean
74
75
76
77
78
79
|
# File 'lib/ledger_sync/resource.rb', line 74
def self.serialize_attribute?(sattr)
sattr = sattr.to_sym
return true if resource_attributes.key?(sattr)
false
end
|
Instance Method Details
#==(other) ⇒ Object
81
82
83
|
# File 'lib/ledger_sync/resource.rb', line 81
def ==(other)
other.fingerprint == fingerprint
end
|
#assign_attribute(name, value) ⇒ Object
31
32
33
34
|
# File 'lib/ledger_sync/resource.rb', line 31
def assign_attribute(name, value)
public_send("#{name}=", value)
self
end
|
#assign_attributes(**keywords) ⇒ Object
36
37
38
39
|
# File 'lib/ledger_sync/resource.rb', line 36
def assign_attributes(**keywords)
keywords.each { |k, v| assign_attribute(k, v) }
self
end
|
#changed? ⇒ Boolean
41
42
43
|
# File 'lib/ledger_sync/resource.rb', line 41
def changed?
super || resource_attributes.references_many.select(&:changed?).any?
end
|
#changes ⇒ Object
45
46
47
|
# File 'lib/ledger_sync/resource.rb', line 45
def changes
super.merge(Hash[resource_attributes.references_many.map { |ref| [ref.name, ref.changes['value']] if ref.changed? }.compact])
end
|
#dup ⇒ Object
49
50
51
|
# File 'lib/ledger_sync/resource.rb', line 49
def dup
Marshal.load(Marshal.dump(self))
end
|
#klass_from_resource_type(obj) ⇒ Object
#to_h ⇒ Object
57
58
59
|
# File 'lib/ledger_sync/resource.rb', line 57
def to_h
resource_attributes.to_h.merge(dirty_attributes_to_h)
end
|