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.
Files changed (165) hide show
  1. checksums.yaml +4 -4
  2. data/.overcommit.yml +30 -0
  3. data/.travis.yml +6 -1
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +11 -5
  6. data/Rakefile +2 -0
  7. data/bin/console +1 -0
  8. data/bin/quickbooks_online_oauth_server.rb +5 -4
  9. data/documentation/generators/generator.rb +4 -4
  10. data/documentation/site/LICENSE.md +14 -14
  11. data/documentation/site/_includes/header.html +34 -34
  12. data/documentation/site/_includes/section_content.html +25 -30
  13. data/documentation/site/_includes/section_cta.html +20 -24
  14. data/documentation/site/_includes/section_grid.html +39 -54
  15. data/documentation/site/_includes/section_hero.html +19 -24
  16. data/documentation/site/_includes/submenu.html +6 -7
  17. data/documentation/site/_layouts/advanced.html +0 -1
  18. data/documentation/site/_layouts/guides.html +2 -2
  19. data/documentation/site/_layouts/page.html +2 -2
  20. data/documentation/site/_plugins/filters.rb +3 -3
  21. data/documentation/site/_templates/reference/resources/resource.md.erb +14 -0
  22. data/documentation/site/assets/js/plugins.js +1 -1
  23. data/documentation/site/guides/architecture/searchers.md +3 -3
  24. data/documentation/site/reference/netsuite/resources/account.md +6 -0
  25. data/documentation/site/reference/netsuite/resources/check.md +6 -0
  26. data/documentation/site/reference/netsuite/resources/check_line_item.md +4 -0
  27. data/documentation/site/reference/netsuite/resources/currency.md +4 -0
  28. data/documentation/site/reference/netsuite/resources/customer.md +6 -0
  29. data/documentation/site/reference/netsuite/resources/customer_deposit.md +6 -0
  30. data/documentation/site/reference/netsuite/resources/department.md +6 -0
  31. data/documentation/site/reference/netsuite/resources/deposit.md +4 -0
  32. data/documentation/site/reference/netsuite/resources/deposit_line_item.md +4 -0
  33. data/documentation/site/reference/netsuite/resources/invoice.md +4 -0
  34. data/documentation/site/reference/netsuite/resources/invoice_line_item.md +4 -0
  35. data/documentation/site/reference/netsuite/resources/item.md +4 -0
  36. data/documentation/site/reference/netsuite/resources/journal_entry.md +4 -0
  37. data/documentation/site/reference/netsuite/resources/journal_entry_line_item.md +4 -0
  38. data/documentation/site/reference/netsuite/resources/ledger_class.md +6 -0
  39. data/documentation/site/reference/netsuite/resources/location.md +6 -0
  40. data/documentation/site/reference/netsuite/resources/resource.md +4 -0
  41. data/documentation/site/reference/netsuite/resources/subsidiary.md +6 -0
  42. data/documentation/site/reference/netsuite/resources/vendor.md +6 -0
  43. data/documentation/site/reference/netsuite_soap/resources/customer.md +4 -0
  44. data/documentation/site/reference/netsuite_soap/resources/resource.md +4 -0
  45. data/documentation/site/reference/netsuite_soap/resources/subsidiary.md +4 -0
  46. data/documentation/site/reference/quickbooks_online/resources/account.md +6 -0
  47. data/documentation/site/reference/quickbooks_online/resources/bill.md +6 -0
  48. data/documentation/site/reference/quickbooks_online/resources/bill_line_item.md +4 -0
  49. data/documentation/site/reference/quickbooks_online/resources/bill_payment.md +4 -0
  50. data/documentation/site/reference/quickbooks_online/resources/bill_payment_line_item.md +4 -0
  51. data/documentation/site/reference/quickbooks_online/resources/currency.md +4 -0
  52. data/documentation/site/reference/quickbooks_online/resources/customer.md +6 -0
  53. data/documentation/site/reference/quickbooks_online/resources/department.md +6 -0
  54. data/documentation/site/reference/quickbooks_online/resources/deposit.md +6 -0
  55. data/documentation/site/reference/quickbooks_online/resources/deposit_line_item.md +4 -0
  56. data/documentation/site/reference/quickbooks_online/resources/expense.md +6 -0
  57. data/documentation/site/reference/quickbooks_online/resources/expense_line_item.md +4 -0
  58. data/documentation/site/reference/quickbooks_online/resources/invoice.md +4 -0
  59. data/documentation/site/reference/quickbooks_online/resources/invoice_sales_line_item.md +4 -0
  60. data/documentation/site/reference/quickbooks_online/resources/item.md +4 -0
  61. data/documentation/site/reference/quickbooks_online/resources/journal_entry.md +6 -0
  62. data/documentation/site/reference/quickbooks_online/resources/journal_entry_line_item.md +4 -0
  63. data/documentation/site/reference/quickbooks_online/resources/ledger_class.md +6 -0
  64. data/documentation/site/reference/quickbooks_online/resources/payment.md +4 -0
  65. data/documentation/site/reference/quickbooks_online/resources/payment_line_item.md +4 -0
  66. data/documentation/site/reference/quickbooks_online/resources/preferences.md +4 -0
  67. data/documentation/site/reference/quickbooks_online/resources/primary_email_addr.md +4 -0
  68. data/documentation/site/reference/quickbooks_online/resources/primary_phone.md +4 -0
  69. data/documentation/site/reference/quickbooks_online/resources/resource.md +4 -0
  70. data/documentation/site/reference/quickbooks_online/resources/subsidiary.md +4 -0
  71. data/documentation/site/reference/quickbooks_online/resources/transfer.md +4 -0
  72. data/documentation/site/reference/quickbooks_online/resources/vendor.md +6 -0
  73. data/documentation/site/reference/stripe/resources/customer.md +4 -0
  74. data/documentation/site/reference/stripe/resources/resource.md +4 -0
  75. data/ledger_sync.gemspec +3 -1
  76. data/lib/ledger_sync.rb +3 -1
  77. data/lib/ledger_sync/concerns/validatable.rb +2 -0
  78. data/lib/ledger_sync/error/operation_errors.rb +1 -1
  79. data/lib/ledger_sync/error/resource_errors.rb +3 -2
  80. data/lib/ledger_sync/ledger_configuration_store.rb +5 -1
  81. data/lib/ledger_sync/ledgers/client.rb +12 -4
  82. data/lib/ledger_sync/ledgers/mixins/infer_serializer_mixin.rb +3 -1
  83. data/lib/ledger_sync/ledgers/netsuite/account/operations/find.rb +1 -1
  84. data/lib/ledger_sync/ledgers/netsuite/client.rb +2 -2
  85. data/lib/ledger_sync/ledgers/netsuite/dashboard_url_helper.rb +1 -1
  86. data/lib/ledger_sync/ledgers/netsuite/error.rb +1 -0
  87. data/lib/ledger_sync/ledgers/netsuite/journal_entry_line_item/deserializer.rb +0 -3
  88. data/lib/ledger_sync/ledgers/netsuite/resources/account.rb +1 -2
  89. data/lib/ledger_sync/ledgers/netsuite/searcher.rb +3 -1
  90. data/lib/ledger_sync/ledgers/netsuite/token.rb +1 -1
  91. data/lib/ledger_sync/ledgers/netsuite/type/deserializer_entity_type.rb +6 -6
  92. data/lib/ledger_sync/ledgers/netsuite/vendor/operations/create.rb +1 -1
  93. data/lib/ledger_sync/ledgers/netsuite/vendor/operations/delete.rb +1 -1
  94. data/lib/ledger_sync/ledgers/netsuite/vendor/operations/find.rb +1 -1
  95. data/lib/ledger_sync/ledgers/netsuite/vendor/operations/update.rb +1 -1
  96. data/lib/ledger_sync/ledgers/netsuite_soap/client.rb +15 -21
  97. data/lib/ledger_sync/ledgers/netsuite_soap/customer/operations/create.rb +2 -0
  98. data/lib/ledger_sync/ledgers/operation.rb +5 -3
  99. data/lib/ledger_sync/ledgers/quickbooks_online/account/operations/create.rb +2 -0
  100. data/lib/ledger_sync/ledgers/quickbooks_online/account/operations/find.rb +2 -0
  101. data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/create.rb +2 -0
  102. data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/find.rb +2 -0
  103. data/lib/ledger_sync/ledgers/quickbooks_online/bill/operations/update.rb +2 -0
  104. data/lib/ledger_sync/ledgers/quickbooks_online/client.rb +12 -4
  105. data/lib/ledger_sync/ledgers/quickbooks_online/customer/searcher.rb +2 -0
  106. data/lib/ledger_sync/ledgers/quickbooks_online/dashboard_url_helper.rb +22 -22
  107. data/lib/ledger_sync/ledgers/quickbooks_online/department/operations/create.rb +2 -0
  108. data/lib/ledger_sync/ledgers/quickbooks_online/department/operations/find.rb +2 -0
  109. data/lib/ledger_sync/ledgers/quickbooks_online/deposit/operations/create.rb +2 -0
  110. data/lib/ledger_sync/ledgers/quickbooks_online/deposit/operations/find.rb +2 -0
  111. data/lib/ledger_sync/ledgers/quickbooks_online/deposit/searcher.rb +1 -0
  112. data/lib/ledger_sync/ledgers/quickbooks_online/deserializer.rb +4 -2
  113. data/lib/ledger_sync/ledgers/quickbooks_online/expense/deserializer.rb +3 -2
  114. data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/create.rb +2 -0
  115. data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/find.rb +2 -0
  116. data/lib/ledger_sync/ledgers/quickbooks_online/expense/operations/update.rb +2 -0
  117. data/lib/ledger_sync/ledgers/quickbooks_online/invoice/operations/find.rb +2 -0
  118. data/lib/ledger_sync/ledgers/quickbooks_online/invoice/operations/update.rb +2 -0
  119. data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/create.rb +2 -0
  120. data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/find.rb +2 -0
  121. data/lib/ledger_sync/ledgers/quickbooks_online/journal_entry/operations/update.rb +2 -0
  122. data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/deserializer.rb +0 -1
  123. data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/operations/create.rb +2 -0
  124. data/lib/ledger_sync/ledgers/quickbooks_online/ledger_class/operations/find.rb +2 -0
  125. data/lib/ledger_sync/ledgers/quickbooks_online/operation.rb +1 -1
  126. data/lib/ledger_sync/ledgers/quickbooks_online/payment/operations/find.rb +2 -0
  127. data/lib/ledger_sync/ledgers/quickbooks_online/payment/operations/update.rb +2 -0
  128. data/lib/ledger_sync/ledgers/quickbooks_online/resources/customer.rb +4 -0
  129. data/lib/ledger_sync/ledgers/quickbooks_online/transfer/operations/create.rb +2 -0
  130. data/lib/ledger_sync/ledgers/quickbooks_online/transfer/operations/find.rb +2 -0
  131. data/lib/ledger_sync/ledgers/quickbooks_online/util/error_matcher.rb +8 -5
  132. data/lib/ledger_sync/ledgers/quickbooks_online/util/ledger_error_parser.rb +3 -3
  133. data/lib/ledger_sync/ledgers/quickbooks_online/util/operation_error_parser.rb +2 -2
  134. data/lib/ledger_sync/ledgers/quickbooks_online/webhook_event.rb +3 -1
  135. data/lib/ledger_sync/ledgers/quickbooks_online/webhook_notification.rb +4 -3
  136. data/lib/ledger_sync/ledgers/response.rb +3 -1
  137. data/lib/ledger_sync/ledgers/stripe/client.rb +1 -1
  138. data/lib/ledger_sync/ledgers/stripe/dashboard_url_helper.rb +1 -1
  139. data/lib/ledger_sync/ledgers/stripe/operation/create.rb +0 -2
  140. data/lib/ledger_sync/ledgers/stripe/operation/delete.rb +0 -2
  141. data/lib/ledger_sync/ledgers/stripe/operation/update.rb +0 -2
  142. data/lib/ledger_sync/resource.rb +3 -1
  143. data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +1 -1
  144. data/lib/ledger_sync/resource_attribute/mixin.rb +3 -3
  145. data/lib/ledger_sync/resource_attribute_set.rb +1 -1
  146. data/lib/ledger_sync/result.rb +7 -12
  147. data/lib/ledger_sync/serialization/deserializer_attribute.rb +6 -2
  148. data/lib/ledger_sync/serializer.rb +3 -1
  149. data/lib/ledger_sync/type/reference_one.rb +1 -1
  150. data/lib/ledger_sync/util/hash_helpers.rb +12 -2
  151. data/lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb +1 -0
  152. data/lib/ledger_sync/util/read_only_object.rb +1 -1
  153. data/lib/ledger_sync/util/resource_converter.rb +12 -8
  154. data/lib/ledger_sync/util/resource_converter/attribute.rb +3 -1
  155. data/lib/ledger_sync/util/resource_converter/attribute_set.rb +2 -1
  156. data/lib/ledger_sync/util/resources_builder.rb +5 -5
  157. data/lib/ledger_sync/version.rb +3 -1
  158. metadata +17 -10
  159. data/documentation/site/reference/architecture/clients.md +0 -33
  160. data/documentation/site/reference/architecture/index.md +0 -14
  161. data/documentation/site/reference/architecture/operations.md +0 -6
  162. data/documentation/site/reference/architecture/resources.md +0 -38
  163. data/documentation/site/reference/architecture/results.md +0 -6
  164. data/documentation/site/reference/architecture/searchers.md +0 -6
  165. data/documentation/site/reference/architecture/serialization.md +0 -6
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LedgerSync
2
4
  module Ledgers
3
5
  module QuickBooksOnline
@@ -24,15 +24,18 @@ module LedgerSync
24
24
  end
25
25
 
26
26
  def error_message
27
- (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('message')) ||
28
- (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Message')) ||
29
- (body && JSON.parse(body).dig('error')) ||
30
- error.message
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
- (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail'))
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 trhottled with: #{error_message}"
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
- message.include?('authenticationfailed') ||
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
- message.include?('authorizationfailed') ||
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
- message.include?('the name supplied already exists')
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
- message.include?('object not found')
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
- raise "Resource class does not exist for QuickBooks Online object: #{quickbooks_online_resource_type}" if resource.nil?
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(payload:, webhook: nil)
17
- @original_payload = payload
18
- @payload = payload.is_a?(String) ? JSON.parse(payload) : payload
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?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LedgerSync
2
4
  module Ledgers
3
5
  class Response
@@ -52,4 +54,4 @@ module LedgerSync
52
54
  end
53
55
  end
54
56
  end
55
- end
57
+ end
@@ -17,7 +17,7 @@ module LedgerSync
17
17
  def url_for(resource:)
18
18
  DashboardURLHelper.new(
19
19
  resource: resource,
20
- base_url: "https://dashboard.stripe.com"
20
+ base_url: 'https://dashboard.stripe.com'
21
21
  ).url
22
22
  end
23
23
 
@@ -13,7 +13,7 @@ module LedgerSync
13
13
  client: self,
14
14
  resource: resource
15
15
  )
16
- end
16
+ end
17
17
  end
18
18
  end
19
19
  end
@@ -8,8 +8,6 @@ module LedgerSync
8
8
  class Operation
9
9
  class Create
10
10
  include Stripe::Operation::Mixin
11
-
12
- private
13
11
  end
14
12
  end
15
13
  end
@@ -8,8 +8,6 @@ module LedgerSync
8
8
  class Operation
9
9
  class Delete
10
10
  include Stripe::Operation::Mixin
11
-
12
- private
13
11
  end
14
12
  end
15
13
  end
@@ -8,8 +8,6 @@ module LedgerSync
8
8
  class Operation
9
9
  class Update
10
10
  include Stripe::Operation::Mixin
11
-
12
- private
13
11
  end
14
12
  end
15
13
  end
@@ -48,7 +48,9 @@ module LedgerSync
48
48
  end
49
49
 
50
50
  def changes
51
- super.merge(Hash[resource_attributes.references_many.map { |ref| [ref.name, ref.changes['value']] if ref.changed? }.compact])
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
- Hash[changes.map { |k, v| [k, v.last] }]
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.keys.each { |e| instance_variable_set("@#{e}", nil) }
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
- Hash[resource_attributes.map { |k, v| [k, v.value] }]
88
+ resource_attributes.transform_values(&:value)
89
89
  end
90
90
  end
91
91
  end
92
- end
92
+ end
@@ -47,7 +47,7 @@ module LedgerSync
47
47
  end
48
48
 
49
49
  def to_h
50
- Hash[attributes.map { |k, v| [k, v.value] }]
50
+ attributes.transform_values(&:value)
51
51
  end
52
52
  end
53
53
  end
@@ -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
- serialize only: %i[
56
- next_searcher
57
- previous_searcher
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(first_attribute) || resource.class.resource_attributes[first_attribute.to_sym].type.resource_class.new,
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[resource_attribute_dot_parts.first.to_sym].type.resource_class
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
- raise 'You cannot provide hash_attribute in args. Pass the value as the first argument.' if args.key?(:hash_attribute)
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(
@@ -23,7 +23,7 @@ module LedgerSync
23
23
  resource_class
24
24
  else
25
25
  [resource_class]
26
- end
26
+ end
27
27
  end
28
28
 
29
29
  private
@@ -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) { |key| key.to_sym rescue key }
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) { |key| key.to_s rescue key }
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
@@ -18,6 +18,7 @@ module LedgerSync
18
18
  ARRAY_METHODS = (SHARED_METHODS | %i[]).freeze
19
19
 
20
20
  HASH_METHODS = (SHARED_METHODS | %i[
21
+ each_key
21
22
  each_value
22
23
  fetch
23
24
  key?
@@ -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 { |k, _| e.to_sym == :raw }.each do |name, attr_settings|
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
- if source.is_a?(Hash) && args.key?(:only_changes)
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[destination_attribute_dot_parts.first.to_sym].type.resource_class
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}: #{attribute.destination_attribute}"
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(external_id:, type:)
40
- external_id = external_id.to_sym
41
- type = type.to_sym
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LedgerSync
2
- VERSION = '1.4.2'.freeze
4
+ VERSION = '1.4.4'
3
5
  end
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.2
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
- rubyforge_project:
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.