fulfil_api 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31bfb876f7d82e4d803cbacf7b3628f5acb66c086188e1c56c50a37dfe6cb6f4
4
- data.tar.gz: db1418268779073af449b43f71ccc47a8a4ad1db92c3261b7d22d9821f5155e0
3
+ metadata.gz: 65225f0a5c01020f7d50c09468555157a52ffc8454b99e0937b63321c11b1e29
4
+ data.tar.gz: 0cf0e22367baff564776329df08318aad4ab27b75b53f669b8f0a0c68d8ecbc8
5
5
  SHA512:
6
- metadata.gz: 5cdefd3a083ef390084db3a04276c49c02243b0cf39b52f9c6146657f712f68251e3087f636d789978536f106d1a59f1b3c18f014ebc2c6330501654cc94a08a
7
- data.tar.gz: 0522da7f4f12ebf1753df8512a716a7c496c11d9f0740ea599ecbfc742b7ef026ca4324769d6bba5f2d37ee16ee4cb963baa5d318d46ea9020538c390fe98e02
6
+ metadata.gz: a3f3dc9ad0b7ae0915df9c16ab407f71a7394baa33cd8518b26caa562fbabbc4c5a8dbc6981f39cc725fb86b7f13eefdba1605c31b4854148531b4ccfc0e3266
7
+ data.tar.gz: c58d7de83e14f54f07b9035cceb7c227ee7c1c6b623c73f3d26ce74700b1cccc383d7d17b9a1e265c7cbab5e6383d4e7921acee85f743b4d5349efe375baba55
@@ -38,11 +38,25 @@ module FulfilApi
38
38
  #
39
39
  # $ resource.assign_attributes({ "warehouse.name" => "Toronto", "warehouse" => 10 })
40
40
  # => <FulfilApi::Resource @attributes={"warehouse" => { "id" => 10, "name" => "Toronto" }} />
41
+ #
42
+ # @example a nested relation with a string as ID
43
+ #
44
+ # $ resource.assign_attributes({ "shipment" => "stock.shipment.out,12", "shipment.number": "CS1234" })
45
+ # => <FulfilApi::Resource @attributes={"warehouse" => { "id" => 12, "number" => "CS1234" }} />
41
46
  @attributes = @attributes.deep_merge(attribute) do |_key, current_value, other_value|
42
- if current_value.is_a?(Integer) && other_value.is_a?(Hash)
43
- { "id" => current_value }.deep_merge(other_value)
44
- elsif current_value.is_a?(Hash) && other_value.is_a?(Integer)
45
- current_value.deep_merge({ "id" => other_value })
47
+ extract_id = lambda { |possible_id|
48
+ possible_id =~ /\A[\w-]+(?:\.[\w-]+){1,2},(?<id>\d+)\z/ ? Regexp.last_match[:id].to_i : nil
49
+ }
50
+
51
+ case [current_value, other_value]
52
+ in [String => str, Hash] if (id = extract_id.call(str))
53
+ { "id" => id }.merge(other_value)
54
+ in [Integer, Hash]
55
+ { "id" => current_value }.merge(other_value)
56
+ in [Hash, Integer]
57
+ current_value.merge({ "id" => other_value })
58
+ in [Hash, String => str] if (id = extract_id.call(str))
59
+ current_value.merge({ "id" => id })
46
60
  else
47
61
  other_value
48
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FulfilApi
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulfil_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Vermaas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-16 00:00:00.000000000 Z
11
+ date: 2025-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport