Keyword Arguments
LedgerSync heavily uses ruby keyword arguments so as to make it clear what values are being passed and which attributes are required. When this README says something like “the fun_function
function takes the argument foo
” that translates to fun_function(foo: :some_value)
.
Fingerprints
Most objects in LedgerSync can be fingerprinted by calling the instance method fingerprint
. For example:
puts LedgerSync::Customer.new.fingerprint # "b3eab7ec00431a4ae0468fee72e5ba8f"
puts LedgerSync::Customer.new.fingerprint == LedgerSync::Customer.new.fingerprint # true
puts LedgerSync::Customer.new.fingerprint == LedgerSync::Customer.new(name: :foo).fingerprint # false
puts LedgerSync::Customer.new.fingerprint == LedgerSync::Payment.new.fingerprint # false
Fingerprints are used to compare objects. This method is used in de-duping objects, as it only considers the data inside and not the instance itself (as shown above).
Serialization
Most objects in LedgerSync can be serialized by calling the instance method serialize
. For example:
puts LedgerSync::Payment.new(
customer: LedgerSync::Customer.new
)
{
root: "LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d",
objects: {
"LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d": {
id: "LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d",
object: "LedgerSync::Payment",
fingeprint: "8eed81c0177801a001f2544f0c85e21d",
data: {
currency: nil,
amount: nil,
customer: {
object: "reference",
id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f"
},
external_id: "",
ledger_id: nil,
}
},
"LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f": {
id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f",
object: "LedgerSync::Customer",
fingeprint: "b3eab7ec00431a4ae0468fee72e5ba8f",
data: {
name: nil,
email: nil,
phone_number: nil,
external_id: "",
ledger_id: nil
}
}
}
}
The serialization of any object follows the same structure. There is a :root
key that holds the ID of the root object. There is also an :objects
hash that contains all of the objects for this serialization. As you can see, unique nested objects listed in the :objects
hash and referenced using a “reference object”, in this case:
{
object: "reference",
id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f"
}