payload-translator 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7e0f8bfa9b529a0adb567c8ebccdad2edd6ad64a1853a3ff49cf772ee46cf76
4
- data.tar.gz: 0e73870879ff49b8ec75976df58af3054206fdc77888588c6d863184350c8a78
3
+ metadata.gz: 1daf169454e82e6d9ad3687a000be711b8ec35aa8301241da1a9b367f440364f
4
+ data.tar.gz: 9cd34aac2ed951140dfbb9be2f0e4eefb449b3b58aa5e48dbfcf30023d748f71
5
5
  SHA512:
6
- metadata.gz: 53c2c2a1a96f8c6483b415655c2566efa85c401fa0ac3fec8e637c6277fec188def4a266d5349a6f16ccf000b0b7f2e54030870318c45fbfce633ea40043cee2
7
- data.tar.gz: 2f8df32464185ef5c8c7169b931bd7961657d83814f346c3094b7b4ae9b248303ec201fcf7e8465a27cab7206069b49669d540770e0137069af7b60324087451
6
+ metadata.gz: 86e80c6da904c003d38e46dd8d142f460be0bf233fc9466d11aca7904cf127ad1917df38c8642a7a1aec50259b85389b31f8807442fc5644ecf4df7ec0e49979
7
+ data.tar.gz: f512af0bfa4c7639bd6335e1ad8d0b312b1457c180231ecc023e77989358ad89f98c806a034adb9fb18770c4084a0f3aaccb66403d287d80bff8e4d32363e5cd
@@ -51,14 +51,7 @@ module PayloadTranslator
51
51
  end
52
52
 
53
53
  def search_value(field_or_fields)
54
- if field_or_fields.is_a?(Array)
55
- field = field_or_fields.find { |field| payload[field] }
56
- payload.fetch(field) { config["$default"] }
57
- elsif field_or_fields =~ /\./
58
- payload.dig(*field_or_fields.split(".")) || config["$default"]
59
- else
60
- payload.fetch(field_or_fields) { config["$default"] }
61
- end
54
+ Payload.search_value(payload, field_or_fields, config["$default"])
62
55
  end
63
56
 
64
57
  def with_formatter
@@ -0,0 +1,16 @@
1
+ module PayloadTranslator
2
+ class Payload
3
+ def self.fetch_field(payload, field_or_fields)
4
+ return field_or_fields unless field_or_fields.is_a?(Array)
5
+
6
+ field_or_fields.find { |field| search_value(payload, field) }
7
+ end
8
+
9
+ def self.search_value(payload, field, default = nil)
10
+ field = fetch_field(payload, field)
11
+ return payload.dig(*field.split(".")) if field =~ /\./
12
+
13
+ payload.fetch(field, default)
14
+ end
15
+ end
16
+ end
@@ -13,5 +13,5 @@ module PayloadTranslator
13
13
  configuration
14
14
  end
15
15
 
16
- VERSION = "0.2.0"
16
+ VERSION = "0.2.1"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payload-translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Savignano
@@ -35,6 +35,7 @@ files:
35
35
  - lib/payload_translator.rb
36
36
  - lib/payload_translator/config.rb
37
37
  - lib/payload_translator/field_resolver.rb
38
+ - lib/payload_translator/payload.rb
38
39
  - lib/payload_translator/service.rb
39
40
  homepage: https://github.com/devmasx/payload-translator
40
41
  licenses: