gecko-ruby 0.9.1 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/config/rubocop_linter_action.yml +7 -0
- data/.github/workflows/testing.yml +26 -0
- data/.rubocop.yml +23 -16
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/gecko-ruby.gemspec +11 -10
- data/generate.thor +4 -1
- data/lib/gecko-ruby.rb +2 -0
- data/lib/gecko.rb +3 -0
- data/lib/gecko/client.rb +17 -14
- data/lib/gecko/ext/liquid_compat.rb +10 -10
- data/lib/gecko/ext/log_subscriber.rb +6 -6
- data/lib/gecko/helpers/association_helper.rb +14 -12
- data/lib/gecko/helpers/inspection_helper.rb +4 -2
- data/lib/gecko/helpers/record_helper.rb +2 -0
- data/lib/gecko/helpers/serialization_helper.rb +5 -1
- data/lib/gecko/helpers/validation_helper.rb +3 -1
- data/lib/gecko/record/account.rb +4 -1
- data/lib/gecko/record/address.rb +2 -0
- data/lib/gecko/record/base.rb +5 -3
- data/lib/gecko/record/base_adapter.rb +33 -22
- data/lib/gecko/record/company.rb +3 -0
- data/lib/gecko/record/contact.rb +2 -0
- data/lib/gecko/record/currency.rb +2 -0
- data/lib/gecko/record/exceptions.rb +2 -0
- data/lib/gecko/record/fulfillment.rb +2 -0
- data/lib/gecko/record/fulfillment_line_item.rb +2 -1
- data/lib/gecko/record/image.rb +13 -8
- data/lib/gecko/record/invoice.rb +7 -3
- data/lib/gecko/record/invoice_line_item.rb +2 -1
- data/lib/gecko/record/location.rb +2 -0
- data/lib/gecko/record/note.rb +2 -0
- data/lib/gecko/record/order.rb +2 -0
- data/lib/gecko/record/order_line_item.rb +3 -0
- data/lib/gecko/record/payment_method.rb +15 -0
- data/lib/gecko/record/payment_term.rb +2 -1
- data/lib/gecko/record/product.rb +4 -0
- data/lib/gecko/record/purchase_order.rb +2 -1
- data/lib/gecko/record/purchase_order_line_item.rb +2 -1
- data/lib/gecko/record/tax_type.rb +2 -1
- data/lib/gecko/record/user.rb +3 -1
- data/lib/gecko/record/variant.rb +9 -7
- data/lib/gecko/record/webhook.rb +3 -1
- data/lib/gecko/version.rb +3 -1
- data/test/client_test.rb +4 -2
- data/test/fixtures/vcr_cassettes/images.yml +1 -1
- data/test/fixtures/vcr_cassettes/payment_methods.yml +69 -0
- data/test/fixtures/vcr_cassettes/payment_methods_count.yml +66 -0
- data/test/gecko_test.rb +2 -0
- data/test/helpers/association_helper_test.rb +7 -5
- data/test/helpers/inspection_helper_test.rb +6 -4
- data/test/helpers/serialization_helper_test.rb +16 -14
- data/test/helpers/validation_helper_test.rb +3 -1
- data/test/record/account_adapter_test.rb +2 -0
- data/test/record/address_adapter_test.rb +2 -0
- data/test/record/address_test.rb +2 -0
- data/test/record/company_adapter_test.rb +2 -0
- data/test/record/company_test.rb +2 -0
- data/test/record/contact_adapter_test.rb +2 -0
- data/test/record/contact_test.rb +3 -1
- data/test/record/currency_adapter_test.rb +2 -0
- data/test/record/currency_test.rb +2 -0
- data/test/record/fulfillment_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_adapter_test.rb +2 -0
- data/test/record/fulfillment_line_item_test.rb +2 -0
- data/test/record/fulfillment_test.rb +4 -2
- data/test/record/image_adapter_test.rb +2 -0
- data/test/record/image_test.rb +18 -0
- data/test/record/invoice_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_adapter_test.rb +2 -0
- data/test/record/invoice_line_item_test.rb +2 -0
- data/test/record/invoice_test.rb +2 -0
- data/test/record/location_adapter_test.rb +2 -0
- data/test/record/location_test.rb +2 -0
- data/test/record/note_test.rb +2 -0
- data/test/record/order_adapter_test.rb +2 -0
- data/test/record/order_line_item_adapter_test.rb +2 -0
- data/test/record/order_line_item_test.rb +2 -0
- data/test/record/order_test.rb +2 -0
- data/test/record/payment_method_adapter_test.rb +16 -0
- data/test/record/payment_method_test.rb +20 -0
- data/test/record/payment_term_adapter_test.rb +2 -0
- data/test/record/payment_term_test.rb +2 -0
- data/test/record/product_adapter_test.rb +2 -0
- data/test/record/product_test.rb +2 -0
- data/test/record/purchase_order_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_adapter_test.rb +2 -0
- data/test/record/purchase_order_line_item_test.rb +2 -0
- data/test/record/purchase_order_test.rb +2 -0
- data/test/record/tax_type_adapter_test.rb +2 -0
- data/test/record/tax_type_test.rb +2 -0
- data/test/record/user_adapter_test.rb +2 -0
- data/test/record/user_test.rb +2 -0
- data/test/record/variant_adapter_test.rb +2 -0
- data/test/record/variant_test.rb +6 -4
- data/test/record/webhook_test.rb +2 -0
- data/test/support/let.rb +2 -0
- data/test/support/shared_adapter_examples.rb +35 -31
- data/test/support/shared_record_examples.rb +3 -1
- data/test/support/shared_sideloaded_data_parsing_examples.rb +2 -1
- data/test/support/testing_adapter.rb +2 -0
- data/test/support/vcr_support.rb +2 -0
- data/test/test_helper.rb +12 -0
- metadata +33 -23
- data/.travis.yml +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c97b7ad1371972ed3a07bb3745d1d70659d408e143364ddc46ad443765fd7f1d
|
4
|
+
data.tar.gz: e88e6fd28b7b52097ba0959317f671ccd97e07a85d5bb81c9883b38922dfdad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7139cb60747d866cf6e1a12ffda87c930d8282a17baab4b4e22cbc74c985532aa64bca5053465f0fc3f7f7edda278dcc72460a619f1bb6a377751e95b431f9fa
|
7
|
+
data.tar.gz: b72da9d0b232d076d6a18a5e4dc69a6ef408f71e59beea4f9f28b3627f47e2d329e1e867d2defd7dc2c7f7dada2fc7af501926fd5cfb04205149797f9ccce510
|
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
name: Ruby Tests
|
3
|
+
|
4
|
+
'on': [push, pull_request]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby: ['2.4', '2.5', '2.6', '2.7']
|
12
|
+
name: Ruby ${{ matrix.ruby }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: actions/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
18
|
+
- name: Run Tests
|
19
|
+
run: |
|
20
|
+
gem install bundler --no-document
|
21
|
+
bundle install --jobs 4 --retry 3
|
22
|
+
bundle exec rake
|
23
|
+
- name: Rubocop
|
24
|
+
uses: andrewmcodes/rubocop-linter-action@v3.1.0
|
25
|
+
env:
|
26
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
DisplayCopNames: true
|
3
|
+
Exclude:
|
4
|
+
- 'bin/*'
|
5
|
+
- 'generate.thor'
|
3
6
|
|
4
7
|
# class Example
|
5
8
|
# ...
|
@@ -9,33 +12,34 @@ AllCops:
|
|
9
12
|
Layout/AccessModifierIndentation:
|
10
13
|
EnforcedStyle: outdent
|
11
14
|
|
12
|
-
Style/Blocks:
|
13
|
-
Enabled: false
|
14
|
-
|
15
|
-
# Allows foo(bar: baz)
|
16
|
-
Style/BracesAroundHashParameters:
|
17
|
-
Enabled: false
|
18
|
-
|
19
15
|
Layout/DotPosition:
|
20
16
|
EnforcedStyle: leading
|
21
17
|
|
22
|
-
Layout/
|
18
|
+
Layout/FirstHashElementIndentation:
|
23
19
|
EnforcedStyle: consistent
|
24
20
|
|
25
|
-
|
21
|
+
Layout/LineLength:
|
26
22
|
Max: 120
|
27
23
|
|
28
|
-
|
29
|
-
|
24
|
+
Layout/HashAlignment:
|
25
|
+
EnforcedColonStyle: table
|
30
26
|
|
31
|
-
|
32
|
-
|
27
|
+
Metrics/AbcSize:
|
28
|
+
Exclude:
|
29
|
+
- 'test/**/*.rb'
|
30
|
+
|
31
|
+
Naming/FileName:
|
32
|
+
Exclude:
|
33
|
+
- 'lib/gecko-ruby.rb'
|
34
|
+
|
35
|
+
Naming/PredicateName:
|
33
36
|
Enabled: false
|
34
37
|
|
35
|
-
|
38
|
+
Naming/AccessorMethodName:
|
36
39
|
Enabled: false
|
37
40
|
|
38
|
-
|
41
|
+
# We like neatly-aligned code
|
42
|
+
Layout/SpaceBeforeFirstArg:
|
39
43
|
Enabled: false
|
40
44
|
|
41
45
|
# Allow single or double quotes
|
@@ -63,7 +67,10 @@ Layout/MultilineOperationIndentation:
|
|
63
67
|
Enabled: false
|
64
68
|
|
65
69
|
Style/ClassAndModuleChildren:
|
66
|
-
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/Documentation:
|
73
|
+
Enabled: false
|
67
74
|
|
68
75
|
Style/DoubleNegation:
|
69
76
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.12.1 (2020-07-20)
|
2
|
+
- Add `Gecko::Record::PaymentMethod` model.
|
3
|
+
|
4
|
+
## 0.12.0 (2020-07-09)
|
5
|
+
- Silence warnings in Ruby 2.7
|
6
|
+
- Ensure response is passed to `ActiveSupport::Notifications` on error
|
7
|
+
- Ensure `adapter.last_response` is set on error response
|
8
|
+
|
9
|
+
## 0.11.1 (2020-04-30)
|
10
|
+
- Fix addresses on Invoice
|
11
|
+
|
12
|
+
## 0.11.0 (2020-04-29)
|
13
|
+
- Store create/update responses under `adapter.last_response` as well.
|
14
|
+
|
15
|
+
## 0.10.0 (2020-04-06)
|
16
|
+
- Add extra delegated attributes to invoice record
|
17
|
+
- [BREAKING] Update Image record to latest API with product and multiple variant support
|
18
|
+
|
1
19
|
## 0.9.1 (2019-07-29)
|
2
20
|
- Fix issue with LiquidCompat that broke during refactor
|
3
21
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# TradeGecko RubyGem
|
1
|
+
# TradeGecko RubyGem ![Build Status](https://github.com/tradegecko/gecko/workflows/Ruby%20Tests/badge.svg) [![Code Climate](https://codeclimate.com/github/tradegecko/gecko.png)](https://codeclimate.com/github/tradegecko/gecko)
|
2
2
|
The official TradeGecko API RubyGem
|
3
3
|
|
4
4
|
## Introduction
|
data/Rakefile
CHANGED
data/gecko-ruby.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'gecko/version'
|
5
6
|
|
@@ -8,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.version = Gecko::VERSION
|
9
10
|
spec.authors = ["Bradley Priest"]
|
10
11
|
spec.email = ['bradley@tradegecko.com']
|
11
|
-
spec.description =
|
12
|
+
spec.description = 'A Ruby interface to the TradeGecko API.'
|
12
13
|
spec.summary = spec.description
|
13
14
|
spec.homepage = 'https://github.com/tradegecko/gecko/'
|
14
15
|
spec.license = 'MIT'
|
@@ -19,17 +20,17 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler"
|
22
|
-
spec.add_development_dependency "
|
23
|
+
spec.add_development_dependency "dotenv"
|
23
24
|
spec.add_development_dependency "minitest"
|
24
|
-
spec.add_development_dependency "vcr"
|
25
|
-
spec.add_development_dependency "webmock"
|
26
25
|
spec.add_development_dependency "mocha"
|
27
|
-
spec.add_development_dependency "timecop"
|
28
|
-
spec.add_development_dependency "dotenv"
|
29
|
-
spec.add_development_dependency "thor"
|
30
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "thor"
|
29
|
+
spec.add_development_dependency "timecop"
|
30
|
+
spec.add_development_dependency "vcr"
|
31
|
+
spec.add_development_dependency "webmock"
|
31
32
|
|
33
|
+
spec.add_dependency "activesupport"
|
32
34
|
spec.add_dependency "oauth2", "> 1.1.0"
|
33
35
|
spec.add_dependency "virtus"
|
34
|
-
spec.add_dependency "activesupport"
|
35
36
|
end
|
data/generate.thor
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support/inflector'
|
2
4
|
class Generate < Thor
|
3
5
|
include Thor::Actions
|
@@ -7,7 +9,7 @@ class Generate < Thor
|
|
7
9
|
@model_name = model_name
|
8
10
|
@file_name = model_name.underscore
|
9
11
|
@plural = ask "What is the underscore plural of #{@model_name}? (#{@file_name}s):"
|
10
|
-
@plural =
|
12
|
+
@plural = !@plural.to_s.empty? ? @plural : @file_name + "s"
|
11
13
|
create_file "lib/gecko/record/#{@file_name}.rb", model_template
|
12
14
|
create_file "test/record/#{@file_name}_adapter_test.rb", test_adapter_template
|
13
15
|
create_file "test/record/#{@file_name}_test.rb", test_template
|
@@ -16,6 +18,7 @@ class Generate < Thor
|
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
21
|
+
|
19
22
|
def default_plural?
|
20
23
|
@plural == @file_name + "s"
|
21
24
|
end
|
data/lib/gecko-ruby.rb
CHANGED
data/lib/gecko.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'virtus'
|
2
4
|
require 'active_support/inflector'
|
3
5
|
require 'active_support/notifications'
|
@@ -30,6 +32,7 @@ require 'gecko/record/user'
|
|
30
32
|
require 'gecko/record/purchase_order'
|
31
33
|
require 'gecko/record/purchase_order_line_item'
|
32
34
|
require 'gecko/record/tax_type'
|
35
|
+
require 'gecko/record/payment_method'
|
33
36
|
require 'gecko/record/payment_term'
|
34
37
|
require 'gecko/record/webhook'
|
35
38
|
|
data/lib/gecko/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'oauth2/version'
|
3
5
|
require 'gecko/version'
|
@@ -31,6 +33,7 @@ module Gecko
|
|
31
33
|
record :PurchaseOrder
|
32
34
|
record :PurchaseOrderLineItem
|
33
35
|
record :TaxType
|
36
|
+
record :PaymentMethod
|
34
37
|
record :PaymentTerm
|
35
38
|
record :Webhook
|
36
39
|
|
@@ -57,7 +60,7 @@ module Gecko
|
|
57
60
|
# @return [undefined]
|
58
61
|
#
|
59
62
|
# @api private
|
60
|
-
def initialize(client_id, client_secret, options={})
|
63
|
+
def initialize(client_id, client_secret, options = {})
|
61
64
|
setup_oauth_client(client_id, client_secret, options)
|
62
65
|
end
|
63
66
|
|
@@ -107,29 +110,29 @@ module Gecko
|
|
107
110
|
#
|
108
111
|
# @api private
|
109
112
|
def adapter_for(klass_name)
|
110
|
-
|
113
|
+
public_send(klass_name.to_sym)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.default_headers
|
117
|
+
{
|
118
|
+
'User-Agent' => ["Gecko/#{Gecko::VERSION}",
|
119
|
+
"OAuth2/#{OAuth2::Version}",
|
120
|
+
"Faraday/#{Faraday::VERSION}",
|
121
|
+
"Ruby/#{RUBY_VERSION}"].join(' ')
|
122
|
+
}
|
111
123
|
end
|
112
124
|
|
113
125
|
private
|
114
126
|
|
115
127
|
def setup_oauth_client(client_id, client_secret, options)
|
116
128
|
defaults = {
|
117
|
-
site:
|
118
|
-
authorize_url:
|
129
|
+
site: 'https://api.tradegecko.com',
|
130
|
+
authorize_url: 'https://go.tradegecko.com/oauth/authorize',
|
119
131
|
connection_opts: {
|
120
|
-
headers:
|
132
|
+
headers: self.class.default_headers
|
121
133
|
}
|
122
134
|
}
|
123
135
|
@oauth_client = OAuth2::Client.new(client_id, client_secret, defaults.merge(options))
|
124
136
|
end
|
125
|
-
|
126
|
-
def self.default_headers
|
127
|
-
{
|
128
|
-
'User-Agent' => ["Gecko/#{Gecko::VERSION}",
|
129
|
-
"OAuth2/#{OAuth2::Version.to_s}",
|
130
|
-
"Faraday/#{Faraday::VERSION}",
|
131
|
-
"Ruby/#{RUBY_VERSION}"].join(' ')
|
132
|
-
}
|
133
|
-
end
|
134
137
|
end
|
135
138
|
end
|
@@ -56,20 +56,20 @@ module Gecko
|
|
56
56
|
|
57
57
|
## Override Liquid::Drop#invoke_drop to also check method arity
|
58
58
|
def invoke_drop(method_or_key)
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
return unless invokable_methods.include?(method_or_key.to_s) && method_arity(method_or_key.to_sym) <= 0
|
60
|
+
|
61
|
+
public_send(method_or_key)
|
62
62
|
end
|
63
63
|
|
64
|
-
|
64
|
+
alias [] invoke_drop
|
65
65
|
|
66
66
|
## Override Liquid::Drop#invokable_methods to add extra checks
|
67
67
|
def invokable_methods
|
68
68
|
@invokable_methods ||= begin
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
available_methods = (
|
69
|
+
denylist = Gecko::Record::Base.public_instance_methods + Liquid::Drop.public_instance_methods
|
70
|
+
denylist -= %i[to_liquid id created_at updated_at]
|
71
|
+
allowlist = public_methods + @delegate.public_methods
|
72
|
+
available_methods = (allowlist - denylist).map(&:to_s)
|
73
73
|
available_methods.reject! { |method_name| method_name.ends_with?("=") }
|
74
74
|
Set.new(available_methods)
|
75
75
|
end
|
@@ -78,8 +78,8 @@ module Gecko
|
|
78
78
|
protected
|
79
79
|
|
80
80
|
def method_arity(method_name)
|
81
|
-
if
|
82
|
-
|
81
|
+
if methods.include?(method_name)
|
82
|
+
method(method_name).arity
|
83
83
|
else
|
84
84
|
@delegate.method(method_name).arity
|
85
85
|
end
|
@@ -13,7 +13,7 @@ class GeckoLogSubscriber < ActiveSupport::LogSubscriber
|
|
13
13
|
@odd = false
|
14
14
|
end
|
15
15
|
|
16
|
-
def request(event)
|
16
|
+
def request(event) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
17
17
|
RequestStore.store[ENV_KEY] = []
|
18
18
|
payload = event.payload
|
19
19
|
|
@@ -27,11 +27,11 @@ class GeckoLogSubscriber < ActiveSupport::LogSubscriber
|
|
27
27
|
name = "#{payload[:model_class]} Load (#{event.duration.round(1)}ms)"
|
28
28
|
query = "#{payload[:verb].to_s.upcase} /#{request_path}"
|
29
29
|
|
30
|
-
if odd?
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
name = if odd?
|
31
|
+
color(name, CYAN, true)
|
32
|
+
else
|
33
|
+
color(name, MAGENTA, true)
|
34
|
+
end
|
35
35
|
|
36
36
|
query = color(query, nil, true)
|
37
37
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gecko
|
2
4
|
module Helpers
|
3
5
|
# Helper for has_many/belongs_to relationships
|
@@ -24,7 +26,7 @@ module Gecko
|
|
24
26
|
# @return [undefined]
|
25
27
|
#
|
26
28
|
# @api public
|
27
|
-
def belongs_to(model_name, options={})
|
29
|
+
def belongs_to(model_name, options = {})
|
28
30
|
class_name = options[:class_name] || model_name.to_s.classify
|
29
31
|
foreign_key = model_name.to_s.foreign_key.to_sym
|
30
32
|
|
@@ -55,22 +57,22 @@ module Gecko
|
|
55
57
|
# @return [undefined]
|
56
58
|
#
|
57
59
|
# @api public
|
58
|
-
def has_many(association_name, options={})
|
60
|
+
def has_many(association_name, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
59
61
|
model_name = association_name.to_s.singularize
|
60
62
|
class_name = options[:class_name] || model_name.classify
|
61
63
|
foreign_key = model_name.foreign_key.pluralize.to_sym
|
62
64
|
readonly = options.key?(:readonly) ? options[:readonly] : true
|
63
65
|
|
64
|
-
define_method association_name do
|
66
|
+
define_method association_name do # rubocop:disable Metrics/MethodLength
|
65
67
|
collection_proxies[association_name] ||= begin
|
66
|
-
ids =
|
67
|
-
if ids.any?
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
build_collection_proxy(collection, {
|
68
|
+
ids = attributes[foreign_key]
|
69
|
+
collection = if ids.any?
|
70
|
+
@client.adapter_for(class_name).find_many(ids)
|
71
|
+
else
|
72
|
+
[]
|
73
|
+
end
|
74
|
+
|
75
|
+
build_collection_proxy(collection, **{
|
74
76
|
embedded: options[:embedded],
|
75
77
|
class_name: class_name,
|
76
78
|
association_name: association_name
|
@@ -98,7 +100,7 @@ module Gecko
|
|
98
100
|
#
|
99
101
|
# @api private
|
100
102
|
def build_collection_proxy(target, association_name:, class_name:, embedded:)
|
101
|
-
CollectionProxy.new({
|
103
|
+
CollectionProxy.new(**{
|
102
104
|
parent: self,
|
103
105
|
target: target,
|
104
106
|
embedded: embedded,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gecko
|
2
4
|
module Helpers
|
3
5
|
# Helper for providing custom #inspect values to Records
|
@@ -39,9 +41,9 @@ module Gecko
|
|
39
41
|
if value.is_a?(String) && value.length > 50
|
40
42
|
"#{value[0..50]}...".inspect
|
41
43
|
elsif value.is_a?(DateTime) || value.is_a?(Time)
|
42
|
-
%("#{value.strftime(
|
44
|
+
%("#{value.strftime('%Y-%m-%d %H:%M:%S')}")
|
43
45
|
elsif value.is_a?(Date)
|
44
|
-
%("#{value.strftime(
|
46
|
+
%("#{value.strftime('%Y-%m-%d')}")
|
45
47
|
else
|
46
48
|
value.inspect
|
47
49
|
end
|