ledger_sync 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.overcommit.yml +30 -0
- data/.travis.yml +6 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +11 -5
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/bin/quickbooks_online_oauth_server.rb +5 -4
- data/documentation/generators/generator.rb +4 -4
- data/documentation/site/LICENSE.md +14 -14
- data/documentation/site/_includes/header.html +34 -34
- data/documentation/site/_includes/section_content.html +25 -30
- data/documentation/site/_includes/section_cta.html +20 -24
- data/documentation/site/_includes/section_grid.html +39 -54
- data/documentation/site/_includes/section_hero.html +19 -24
- data/documentation/site/_includes/submenu.html +6 -7
- data/documentation/site/_layouts/advanced.html +0 -1
- data/documentation/site/_layouts/guides.html +2 -2
- data/documentation/site/_layouts/page.html +2 -2
- data/documentation/site/_plugins/filters.rb +3 -3
- data/documentation/site/_templates/reference/resources/resource.md.erb +14 -0
- data/documentation/site/assets/js/plugins.js +1 -1
- data/documentation/site/guides/architecture/searchers.md +3 -3
- data/documentation/site/reference/netsuite/resources/account.md +6 -0
- data/documentation/site/reference/netsuite/resources/check.md +6 -0
- data/documentation/site/reference/netsuite/resources/check_line_item.md +4 -0
- data/documentation/site/reference/netsuite/resources/currency.md +4 -0
- data/documentation/site/reference/netsuite/resources/customer.md +6 -0
- data/documentation/site/reference/netsuite/resources/customer_deposit.md +6 -0
- data/documentation/site/reference/netsuite/resources/department.md +6 -0
- data/documentation/site/reference/netsuite/resources/deposit.md +4 -0
- data/documentation/site/reference/netsuite/resources/deposit_line_item.md +4 -0
- data/documentation/site/reference/netsuite/resources/invoice.md +4 -0
- data/documentation/site/reference/netsuite/resources/invoice_line_item.md +4 -0
- data/documentation/site/reference/netsuite/resources/item.md +4 -0
- data/documentation/site/reference/netsuite/resources/journal_entry.md +4 -0
- data/documentation/site/reference/netsuite/resources/journal_entry_line_item.md +4 -0
- data/documentation/site/reference/netsuite/resources/ledger_class.md +6 -0
- data/documentation/site/reference/netsuite/resources/location.md +6 -0
- data/documentation/site/reference/netsuite/resources/resource.md +4 -0
- data/documentation/site/reference/netsuite/resources/subsidiary.md +6 -0
- data/documentation/site/reference/netsuite/resources/vendor.md +6 -0
- data/documentation/site/reference/netsuite_soap/resources/customer.md +4 -0
- data/documentation/site/reference/netsuite_soap/resources/resource.md +4 -0
- data/documentation/site/reference/netsuite_soap/resources/subsidiary.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/account.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/bill.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/bill_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/bill_payment.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/bill_payment_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/currency.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/customer.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/department.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/deposit.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/deposit_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/expense.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/expense_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/invoice.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/invoice_sales_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/journal_entry.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/journal_entry_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/ledger_class.md +6 -0
- data/documentation/site/reference/quickbooks_online/resources/payment.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/payment_line_item.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/preferences.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/primary_email_addr.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/primary_phone.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/resource.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/subsidiary.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/transfer.md +4 -0
- data/documentation/site/reference/quickbooks_online/resources/vendor.md +6 -0
- data/documentation/site/reference/stripe/resources/customer.md +4 -0
- data/documentation/site/reference/stripe/resources/resource.md +4 -0
- data/ledger_sync.gemspec +3 -1
- data/lib/ledger_sync.rb +3 -1
- data/lib/ledger_sync/concerns/validatable.rb +2 -0
- data/lib/ledger_sync/error/operation_errors.rb +1 -1
- data/lib/ledger_sync/error/resource_errors.rb +3 -2
- data/lib/ledger_sync/ledger_configuration_store.rb +5 -1
- data/lib/ledger_sync/ledgers/client.rb +12 -4
- data/lib/ledger_sync/ledgers/mixins/infer_serializer_mixin.rb +3 -1
- data/lib/ledger_sync/ledgers/netsuite/account/operations/find.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/client.rb +2 -2
- data/lib/ledger_sync/ledgers/netsuite/dashboard_url_helper.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/error.rb +1 -0
- data/lib/ledger_sync/ledgers/netsuite/journal_entry_line_item/deserializer.rb +0 -3
- data/lib/ledger_sync/ledgers/netsuite/resources/account.rb +1 -2
- data/lib/ledger_sync/ledgers/netsuite/searcher.rb +3 -1
- data/lib/ledger_sync/ledgers/netsuite/token.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/type/deserializer_entity_type.rb +6 -6
- data/lib/ledger_sync/ledgers/netsuite/vendor/operations/create.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/vendor/operations/delete.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/vendor/operations/find.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite/vendor/operations/update.rb +1 -1
- data/lib/ledger_sync/ledgers/netsuite_soap/client.rb +15 -21
- data/lib/ledger_sync/ledgers/netsuite_soap/customer/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/operation.rb +5 -3
- data/lib/ledger_sync/ledgers/quickbooks_online/account/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/account/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/update.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/client.rb +12 -4
- data/lib/ledger_sync/ledgers/quickbooks_online/customer/searcher.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/dashboard_url_helper.rb +22 -22
- data/lib/ledger_sync/ledgers/quickbooks_online/department/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/department/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/deposit/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/deposit/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/deposit/searcher.rb +1 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/deserializer.rb +4 -2
- data/lib/ledger_sync/ledgers/quickbooks_online/expense/deserializer.rb +3 -2
- data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/update.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/invoice/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/invoice/operations/update.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/update.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/deserializer.rb +0 -1
- data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/operation.rb +1 -1
- data/lib/ledger_sync/ledgers/quickbooks_online/payment/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/payment/operations/update.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/resources/customer.rb +4 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/transfer/operations/create.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/transfer/operations/find.rb +2 -0
- data/lib/ledger_sync/ledgers/quickbooks_online/util/error_matcher.rb +8 -5
- data/lib/ledger_sync/ledgers/quickbooks_online/util/ledger_error_parser.rb +3 -3
- data/lib/ledger_sync/ledgers/quickbooks_online/util/operation_error_parser.rb +2 -2
- data/lib/ledger_sync/ledgers/quickbooks_online/webhook_event.rb +3 -1
- data/lib/ledger_sync/ledgers/quickbooks_online/webhook_notification.rb +4 -3
- data/lib/ledger_sync/ledgers/response.rb +3 -1
- data/lib/ledger_sync/ledgers/stripe/client.rb +1 -1
- data/lib/ledger_sync/ledgers/stripe/dashboard_url_helper.rb +1 -1
- data/lib/ledger_sync/ledgers/stripe/operation/create.rb +0 -2
- data/lib/ledger_sync/ledgers/stripe/operation/delete.rb +0 -2
- data/lib/ledger_sync/ledgers/stripe/operation/update.rb +0 -2
- data/lib/ledger_sync/resource.rb +3 -1
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +1 -1
- data/lib/ledger_sync/resource_attribute/mixin.rb +3 -3
- data/lib/ledger_sync/resource_attribute_set.rb +1 -1
- data/lib/ledger_sync/result.rb +7 -12
- data/lib/ledger_sync/serialization/deserializer_attribute.rb +6 -2
- data/lib/ledger_sync/serializer.rb +3 -1
- data/lib/ledger_sync/type/reference_one.rb +1 -1
- data/lib/ledger_sync/util/hash_helpers.rb +12 -2
- data/lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb +1 -0
- data/lib/ledger_sync/util/read_only_object.rb +1 -1
- data/lib/ledger_sync/util/resource_converter.rb +12 -8
- data/lib/ledger_sync/util/resource_converter/attribute.rb +3 -1
- data/lib/ledger_sync/util/resource_converter/attribute_set.rb +2 -1
- data/lib/ledger_sync/util/resources_builder.rb +5 -5
- data/lib/ledger_sync/version.rb +3 -1
- metadata +17 -10
- data/documentation/site/reference/architecture/clients.md +0 -33
- data/documentation/site/reference/architecture/index.md +0 -14
- data/documentation/site/reference/architecture/operations.md +0 -6
- data/documentation/site/reference/architecture/resources.md +0 -38
- data/documentation/site/reference/architecture/results.md +0 -6
- data/documentation/site/reference/architecture/searchers.md +0 -6
- data/documentation/site/reference/architecture/serialization.md +0 -6
|
@@ -24,15 +24,18 @@ module LedgerSync
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def error_message
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
return error.message unless body
|
|
28
|
+
|
|
29
|
+
parsed_body = JSON.parse(body)
|
|
30
|
+
|
|
31
|
+
parsed_body.dig('fault', 'error')&.first&.fetch('message') ||
|
|
32
|
+
parsed_body.dig('Fault', 'Error')&.first&.fetch('Message') ||
|
|
33
|
+
parsed_body.dig('error')
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
def detail
|
|
34
37
|
(body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('detail')) ||
|
|
35
|
-
|
|
38
|
+
(body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail'))
|
|
36
39
|
end
|
|
37
40
|
|
|
38
41
|
def code
|
|
@@ -13,7 +13,7 @@ module LedgerSync
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def output_message
|
|
16
|
-
"Request
|
|
16
|
+
"Request throttle with: #{error_message}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def match?
|
|
@@ -33,7 +33,7 @@ module LedgerSync
|
|
|
33
33
|
|
|
34
34
|
def match?
|
|
35
35
|
code == 3200 ||
|
|
36
|
-
|
|
36
|
+
message.include?('authenticationfailed') ||
|
|
37
37
|
message.include?('errorcode=003200')
|
|
38
38
|
end
|
|
39
39
|
end
|
|
@@ -49,7 +49,7 @@ module LedgerSync
|
|
|
49
49
|
|
|
50
50
|
def match?
|
|
51
51
|
code == 3100 ||
|
|
52
|
-
|
|
52
|
+
message.include?('authorizationfailed') ||
|
|
53
53
|
message.include?('errorcode=003100')
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -18,7 +18,7 @@ module LedgerSync
|
|
|
18
18
|
|
|
19
19
|
def match?
|
|
20
20
|
code == 6240 ||
|
|
21
|
-
|
|
21
|
+
message.include?('the name supplied already exists')
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -33,7 +33,7 @@ module LedgerSync
|
|
|
33
33
|
|
|
34
34
|
def match?
|
|
35
35
|
code == 610 ||
|
|
36
|
-
|
|
36
|
+
message.include?('object not found')
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
@@ -65,7 +65,9 @@ module LedgerSync
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def resource!
|
|
68
|
-
|
|
68
|
+
if resource.nil?
|
|
69
|
+
raise "Resource class does not exist for QuickBooks Online object: #{quickbooks_online_resource_type}"
|
|
70
|
+
end
|
|
69
71
|
|
|
70
72
|
resource
|
|
71
73
|
end
|
|
@@ -13,9 +13,10 @@ module LedgerSync
|
|
|
13
13
|
:realm_id,
|
|
14
14
|
:webhook
|
|
15
15
|
|
|
16
|
-
def initialize(
|
|
17
|
-
@original_payload = payload
|
|
18
|
-
@
|
|
16
|
+
def initialize(args = {})
|
|
17
|
+
@original_payload = args.fetch(:payload)
|
|
18
|
+
@webhook = args.fetch(:webhook, nil)
|
|
19
|
+
@payload = original_payload.is_a?(String) ? JSON.parse(original_payload) : original_payload
|
|
19
20
|
|
|
20
21
|
@realm_id = @payload.dig('realmId')
|
|
21
22
|
raise 'Invalid payload: Could not find realmId' if @realm_id.blank?
|
data/lib/ledger_sync/resource.rb
CHANGED
|
@@ -48,7 +48,9 @@ module LedgerSync
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def changes
|
|
51
|
-
super.merge(Hash[resource_attributes.references_many.map
|
|
51
|
+
super.merge(Hash[resource_attributes.references_many.map do |ref|
|
|
52
|
+
[ref.name, ref.changes['value']] if ref.changed?
|
|
53
|
+
end.compact])
|
|
52
54
|
end
|
|
53
55
|
|
|
54
56
|
def class_from_resource_type(obj)
|
|
@@ -36,7 +36,7 @@ module LedgerSync
|
|
|
36
36
|
# Change the dirty change set of {"name" => ["Bill", "Bob"]}
|
|
37
37
|
# to current values of attributes that have changed: {"name" => "Bob"}
|
|
38
38
|
def changes_to_h
|
|
39
|
-
|
|
39
|
+
changes.transform_values(&:last)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def dirty_attributes_to_h
|
|
@@ -55,7 +55,7 @@ module LedgerSync
|
|
|
55
55
|
|
|
56
56
|
def initialize(**data)
|
|
57
57
|
# Initialize empty values
|
|
58
|
-
resource_attributes.
|
|
58
|
+
resource_attributes.each_key { |e| instance_variable_set("@#{e}", nil) }
|
|
59
59
|
|
|
60
60
|
assign_attributes(data)
|
|
61
61
|
|
|
@@ -85,8 +85,8 @@ module LedgerSync
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def serialize_attributes
|
|
88
|
-
|
|
88
|
+
resource_attributes.transform_values(&:value)
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
|
-
end
|
|
92
|
+
end
|
data/lib/ledger_sync/result.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module LedgerSync
|
|
2
4
|
module ResultBase
|
|
3
5
|
module HelperMethods
|
|
4
|
-
def Success(value = nil, *args)
|
|
6
|
+
def Success(value = nil, *args) # rubocop:disable Naming/MethodName
|
|
5
7
|
self::Success.new(value, *args)
|
|
6
8
|
end
|
|
7
9
|
|
|
8
|
-
def Failure(error = nil, *args)
|
|
10
|
+
def Failure(error = nil, *args) # rubocop:disable Naming/MethodName
|
|
9
11
|
self::Failure.new(error, *args)
|
|
10
12
|
end
|
|
11
13
|
end
|
|
@@ -52,22 +54,15 @@ module LedgerSync
|
|
|
52
54
|
|
|
53
55
|
def self.included(base)
|
|
54
56
|
base.class_eval do
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
# TODO: removed next and previous searcher, because it causes a string of them.
|
|
58
|
+
# We should add next_searcher_params which would be easier to serialize.
|
|
59
|
+
simply_serialize only: %i[
|
|
58
60
|
resources
|
|
59
61
|
searcher
|
|
60
62
|
]
|
|
61
63
|
end
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
def self.included(base)
|
|
65
|
-
base.class_eval do
|
|
66
|
-
# TODO: removed next and previous searcher, because it causes a string of them. We should add next_searcher_params which would be easier to serialize.
|
|
67
|
-
simply_serialize only: %i[resources searcher]
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
66
|
def initialize(*args, searcher:, **keywords)
|
|
72
67
|
@resources = searcher.resources
|
|
73
68
|
@searcher = searcher
|
|
@@ -59,7 +59,9 @@ module LedgerSync
|
|
|
59
59
|
resource.public_send(
|
|
60
60
|
"#{first_attribute}=",
|
|
61
61
|
build_resource_value_from_nested_attributes(
|
|
62
|
-
resource.public_send(
|
|
62
|
+
resource.public_send(
|
|
63
|
+
first_attribute
|
|
64
|
+
) || resource.class.resource_attributes[first_attribute.to_sym].type.resource_class.new,
|
|
63
65
|
value,
|
|
64
66
|
remaining_attributes
|
|
65
67
|
)
|
|
@@ -71,7 +73,9 @@ module LedgerSync
|
|
|
71
73
|
|
|
72
74
|
def resource_attribute_class(resource:)
|
|
73
75
|
@resource_attribute_type ||= {}
|
|
74
|
-
@resource_attribute_type[resource] ||= resource.class.resource_attributes[
|
|
76
|
+
@resource_attribute_type[resource] ||= resource.class.resource_attributes[
|
|
77
|
+
resource_attribute_dot_parts.first.to_sym
|
|
78
|
+
].type.resource_class
|
|
75
79
|
end
|
|
76
80
|
end
|
|
77
81
|
end
|
|
@@ -40,7 +40,9 @@ module LedgerSync
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def self.attribute(hash_attribute, args = {}, &block)
|
|
43
|
-
|
|
43
|
+
if args.key?(:hash_attribute)
|
|
44
|
+
raise 'You cannot provide hash_attribute in args. Pass the value as the first argument.'
|
|
45
|
+
end
|
|
44
46
|
|
|
45
47
|
_attribute(
|
|
46
48
|
args.merge(
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'json'
|
|
2
4
|
# Inspired by
|
|
3
5
|
# https://github.com/rails/rails/blob/v6.0.0/activesupport/lib/active_support/core_ext/hash/keys.rb#L116
|
|
@@ -20,7 +22,11 @@ module LedgerSync
|
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def deep_symbolize_keys(hash)
|
|
23
|
-
deep_transform_keys_in_object(hash)
|
|
25
|
+
deep_transform_keys_in_object(hash) do |key|
|
|
26
|
+
key.to_sym
|
|
27
|
+
rescue StandardError
|
|
28
|
+
key
|
|
29
|
+
end
|
|
24
30
|
end
|
|
25
31
|
|
|
26
32
|
def deep_transform_keys_in_object(object, &block)
|
|
@@ -37,7 +43,11 @@ module LedgerSync
|
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
def deep_stringify_keys(hash)
|
|
40
|
-
deep_transform_keys_in_object(hash)
|
|
46
|
+
deep_transform_keys_in_object(hash) do |key|
|
|
47
|
+
key.to_s
|
|
48
|
+
rescue StandardError
|
|
49
|
+
key
|
|
50
|
+
end
|
|
41
51
|
end
|
|
42
52
|
end
|
|
43
53
|
end
|
|
@@ -8,7 +8,7 @@ module LedgerSync
|
|
|
8
8
|
def initialize(args = {})
|
|
9
9
|
@raw = args.with_indifferent_access
|
|
10
10
|
|
|
11
|
-
self.class.attributes.except { |
|
|
11
|
+
self.class.attributes.except { |_k, _| e.to_sym == :raw }.each do |name, attr_settings|
|
|
12
12
|
if attr_settings.key?(:default)
|
|
13
13
|
instance_variable_set(
|
|
14
14
|
"@#{name}",
|
|
@@ -14,20 +14,13 @@ module LedgerSync
|
|
|
14
14
|
source = args.fetch(:source).dup
|
|
15
15
|
source = Util::HashHelpers.deep_stringify_keys(source) if source.is_a?(Hash)
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
raise 'only_changes can only be passed when the source is a resource'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
self.class.attributes.each do |converter_attribute|
|
|
22
|
-
next if only_changes && !source.attribute_changed?(converter_attribute.source_attribute)
|
|
23
|
-
|
|
17
|
+
convertable_attributes(only_changes: only_changes, source: source).each do |converter_attribute|
|
|
24
18
|
args_to_pass = {
|
|
25
19
|
destination: destination,
|
|
26
20
|
source: source
|
|
27
21
|
}
|
|
28
22
|
next if converter_attribute.if_method.present? && !send(converter_attribute.if_method, args_to_pass)
|
|
29
23
|
|
|
30
|
-
|
|
31
24
|
# This is for in place changes
|
|
32
25
|
destination = converter_attribute.build_destination!(args_to_pass)
|
|
33
26
|
end
|
|
@@ -35,6 +28,17 @@ module LedgerSync
|
|
|
35
28
|
destination
|
|
36
29
|
end
|
|
37
30
|
|
|
31
|
+
def convertable_attributes(args = {})
|
|
32
|
+
converter_attributes = self.class.attributes
|
|
33
|
+
source = args.fetch(:source)
|
|
34
|
+
|
|
35
|
+
return converter_attributes unless args[:only_changes] == true
|
|
36
|
+
|
|
37
|
+
raise 'only_changes can only be passed when the source is a resource' if source.is_a?(Hash)
|
|
38
|
+
|
|
39
|
+
converter_attributes.select { |e| source.attribute_changed?(e.source_attribute) }
|
|
40
|
+
end
|
|
41
|
+
|
|
38
42
|
def self._attribute(destination_attribute = nil, args = {}, &block)
|
|
39
43
|
if args.key?(:destination_attribute)
|
|
40
44
|
raise 'You cannot provide destination_attribute in args. Pass the value as the first argument.'
|
|
@@ -79,7 +79,9 @@ module LedgerSync
|
|
|
79
79
|
|
|
80
80
|
def destination_attribute_class(destination:)
|
|
81
81
|
@destination_attribute_type ||= {}
|
|
82
|
-
@destination_attribute_type[destination] ||= destination.class.destination_attributes[
|
|
82
|
+
@destination_attribute_type[destination] ||= destination.class.destination_attributes[
|
|
83
|
+
destination_attribute_dot_parts.first.to_sym
|
|
84
|
+
].type.resource_class
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
def destination_attribute_dot_parts
|
|
@@ -22,7 +22,8 @@ module LedgerSync
|
|
|
22
22
|
def add(attribute)
|
|
23
23
|
unless attribute.destination_attribute.nil?
|
|
24
24
|
if @attribute_keys.key?(attribute.destination_attribute.to_s)
|
|
25
|
-
raise "destination_attribute already defined for #{resource_converter_class.name}:
|
|
25
|
+
raise "destination_attribute already defined for #{resource_converter_class.name}: "\
|
|
26
|
+
"#{attribute.destination_attribute}"
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
@attribute_keys[attribute.destination_attribute] = attribute
|
|
@@ -36,12 +36,12 @@ module LedgerSync
|
|
|
36
36
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
|
-
def build_resource(
|
|
40
|
-
external_id
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
ledger_id = @data.dig(type, external_id, :ledger_id)
|
|
39
|
+
def build_resource(args = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
40
|
+
external_id = args.fetch(:external_id).to_sym
|
|
41
|
+
type = args.fetch(:type).to_sym
|
|
42
|
+
ledger_id = @data.dig(type, external_id, :ledger_id)
|
|
44
43
|
current_data = @data.dig(type, external_id, :data)
|
|
44
|
+
|
|
45
45
|
raise "No data provided for #{type} (ID: #{external_id})" if current_data.nil?
|
|
46
46
|
|
|
47
47
|
resource_class = if ledger == :root
|
data/lib/ledger_sync/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ledger_sync
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Jackson
|
|
@@ -136,6 +136,20 @@ dependencies:
|
|
|
136
136
|
- - "~>"
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '1.9'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: overcommit
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
139
153
|
- !ruby/object:Gem::Dependency
|
|
140
154
|
name: rake
|
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -457,6 +471,7 @@ files:
|
|
|
457
471
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
|
458
472
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
|
459
473
|
- ".gitignore"
|
|
474
|
+
- ".overcommit.yml"
|
|
460
475
|
- ".rubocop.yml"
|
|
461
476
|
- ".rubocop_todo.yml"
|
|
462
477
|
- ".travis.yml"
|
|
@@ -611,13 +626,6 @@ files:
|
|
|
611
626
|
- documentation/site/images/logo.svg
|
|
612
627
|
- documentation/site/index.md
|
|
613
628
|
- documentation/site/overview.md
|
|
614
|
-
- documentation/site/reference/architecture/clients.md
|
|
615
|
-
- documentation/site/reference/architecture/index.md
|
|
616
|
-
- documentation/site/reference/architecture/operations.md
|
|
617
|
-
- documentation/site/reference/architecture/resources.md
|
|
618
|
-
- documentation/site/reference/architecture/results.md
|
|
619
|
-
- documentation/site/reference/architecture/searchers.md
|
|
620
|
-
- documentation/site/reference/architecture/serialization.md
|
|
621
629
|
- documentation/site/reference/index.md
|
|
622
630
|
- documentation/site/reference/netsuite/authentication/_token_based_authentication.md
|
|
623
631
|
- documentation/site/reference/netsuite/authentication/index.md
|
|
@@ -1085,8 +1093,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1085
1093
|
- !ruby/object:Gem::Version
|
|
1086
1094
|
version: '0'
|
|
1087
1095
|
requirements: []
|
|
1088
|
-
|
|
1089
|
-
rubygems_version: 2.7.6.2
|
|
1096
|
+
rubygems_version: 3.0.3
|
|
1090
1097
|
signing_key:
|
|
1091
1098
|
specification_version: 4
|
|
1092
1099
|
summary: Sync common objects to accounting software.
|