Class: LedgerSync::Resource
Direct Known Subclasses
Account, Bill, BillLineItem, Customer, Deposit, DepositLineItem, Expense, ExpenseLineItem, JournalEntry, JournalEntryLineItem, Payment, 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
59
60
61
62
|
# File 'lib/ledger_sync/resource.rb', line 59
def self.inherited(subclass)
subclass.attribute :external_id, type: Type::ID
subclass.attribute :ledger_id, type: Type::ID
end
|
.serialize_attribute?(sattr) ⇒ Boolean
68
69
70
71
72
73
|
# File 'lib/ledger_sync/resource.rb', line 68
def self.serialize_attribute?(sattr)
sattr = sattr.to_sym
return true if resource_attributes.key?(sattr)
false
end
|
Instance Method Details
#==(other) ⇒ Object
75
76
77
|
# File 'lib/ledger_sync/resource.rb', line 75
def ==(other)
other.fingerprint == fingerprint
end
|
#assign_attribute(name, value) ⇒ Object
31
32
33
|
# File 'lib/ledger_sync/resource.rb', line 31
def assign_attribute(name, value)
public_send("#{name}=", value)
end
|
#assign_attributes(**keywords) ⇒ Object
35
36
37
|
# File 'lib/ledger_sync/resource.rb', line 35
def assign_attributes(**keywords)
keywords.each { |k, v| assign_attribute(k, v) }
end
|
#changed? ⇒ Boolean
39
40
41
|
# File 'lib/ledger_sync/resource.rb', line 39
def changed?
super || resource_attributes.references_many.select(&:changed?).any?
end
|
#changes ⇒ Object
43
44
45
|
# File 'lib/ledger_sync/resource.rb', line 43
def changes
super.merge(Hash[resource_attributes.references_many.map { |ref| [ref.name, ref.changes['value']] if ref.changed? }.compact])
end
|
#dup ⇒ Object
47
48
49
|
# File 'lib/ledger_sync/resource.rb', line 47
def dup
Marshal.load(Marshal.dump(self))
end
|
#klass_from_resource_type(obj) ⇒ Object
#to_h ⇒ Object
55
56
57
|
# File 'lib/ledger_sync/resource.rb', line 55
def to_h
resource_attributes.to_h.merge(dirty_attributes_to_h)
end
|