jekyll-spree-client 0.1.18 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll/spree_client.rb +22 -4
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d065883f0802c7520e29ebaa9fad7b624c22d903c190b06450543351603e389
4
- data.tar.gz: 1810529172893e3c5feb437a27817e15d51e1b5bcd494d2b80de2dea44ffedea
3
+ metadata.gz: 8f691ea2cebbd451a912b7dc7ea4ec6cea4a30c8a2b345dd0a2ab5d113ef763f
4
+ data.tar.gz: 9d56c15db95801773a18ad56f0a1263ad0693a007611211f211e7e4a3797744c
5
5
  SHA512:
6
- metadata.gz: a43430f248135eaad2522f0975af3c07cec45e4a4144f226435bfd2b3f097d9d525738d1401450ccbeb34cd3704023588c183a5391ccba1604ea4077d960b773
7
- data.tar.gz: 16e594d12bbc16c8ae40a6b851065a3024897d66cf6585c461a8c6255ad9cc1590276c79cf9ff2920103259b36615f6a9bd13787342cf1586b4c9cae1d285b04
6
+ metadata.gz: f7a0c45963d7ca0ee95f4448873dfe9d9eccc2050f579b00e5faeb215eca6051f1bad615216610fec97817d2e48e7bb3da79b7f537d8157d462ead7b690c8975
7
+ data.tar.gz: 865dbd12ff3369260a90ca5f9cc8e3bb2020209e4bac961d49f32695cd7b97a2a6e59e171d4265f7480fc0b062afb987ba016297a3aa33cddac1121ad1da6dab
@@ -40,7 +40,7 @@ module Jekyll
40
40
  #
41
41
  # @return [Array]
42
42
  def product_fields
43
- @product_fields ||= %w[name description meta_description meta_keywords meta_title pay_what_you_can].freeze
43
+ @product_fields ||= %w[name description meta_description meta_keywords meta_title pay_what_you_can extra_attributes].freeze
44
44
  end
45
45
 
46
46
  # All fields, using during creation
@@ -185,12 +185,17 @@ module Jekyll
185
185
  # @return [true,false]
186
186
  def update(product, variant)
187
187
  # Sync local changes to Spree
188
- remote_product = attributes_from product, product_fields
189
- variant_comparison = attributes_from variant, product_fields
188
+ remote_product = attributes_from(product, product_fields).tap do |a|
189
+ a[:extra_attributes] ||= {}
190
+ end
191
+
192
+ variant_comparison = attributes_from(variant, product_fields).tap do |v|
193
+ v[:extra_attributes] = v[:extra_attributes]&.transform_keys(&:to_sym)
194
+ end
190
195
 
191
196
  # Only when they haven't changed, so we don't waste time sending a
192
197
  # request.
193
- unless remote_product.slice(*variant_comparison.keys) == variant_comparison
198
+ unless compare_hashes(remote_product, variant_comparison)
194
199
  # XXX: We don't have the product ID with the variant but we have
195
200
  # the slug.
196
201
  remote_variant = { id: variant['id'] }.merge!(attributes_from product, variant_only_fields)
@@ -266,5 +271,18 @@ module Jekyll
266
271
  def attributes_from(document_or_hash, fields)
267
272
  (document_or_hash.respond_to?(:data) ? document_or_hash.data : document_or_hash).slice(*fields).transform_keys(&:to_sym)
268
273
  end
274
+
275
+ # Compare two hashes by the keys they share. Some fields we send
276
+ # are not available through the APIv1, like meta_description.
277
+ #
278
+ # @link https://stackoverflow.com/a/15503329
279
+ # @param :h1 [Hash]
280
+ # @param :h2 [Hash]
281
+ # @return [Boolean]
282
+ def compare_hashes(h1, h2)
283
+ (h1.keys & h2.keys).all? do |k|
284
+ h1[k] == h2[k]
285
+ end
286
+ end
269
287
  end
270
288
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-spree-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-01 00:00:00.000000000 Z
11
+ date: 2022-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree-api-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.3
19
+ version: 0.2.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.3
26
+ version: 0.2.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fast_blank
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.1.2
99
+ rubygems_version: 3.3.8
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Spree Ecommerce API client for Jekyll