hash_map 0.5.1 → 0.5.2

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
  SHA1:
3
- metadata.gz: c57bc95e7052c0c47f51335a0ba7b4d155234666
4
- data.tar.gz: 6bfb54eb1d57266248d651a42bb55a495195c287
3
+ metadata.gz: c0a6a8bd9cc92001e37afa91b8f81bb7227cde14
4
+ data.tar.gz: 807954453bc2c7364a174597dda3bcc5d00a409d
5
5
  SHA512:
6
- metadata.gz: 3bb511c4e06c8ce12fc1420238006d0e36a16971bab43cf249b887252a8963e6a300f3b93bfd85e34dc83528c8064ec4ddd95a318ee045efd9b442e250d68640
7
- data.tar.gz: 84296666688feac7b1227b8aa9e9ba0ea97d11f53f4caedc4ce1d5fbf18d4b3d09fe09a435ca0dff0a36a407e05a5cb67917ef0aa3a9d6b274276e4adce5ae0c
6
+ metadata.gz: 7ef4aaabb76f1ea29a981bdfe05ed7fc4c327b08eb578557b2b549f44c55889e711b5e0788f10d59ec628c2fd9f80c9e085a6b9cf31af09001cca72fed03c242
7
+ data.tar.gz: f322f64a2fbd439e47d8cb076a81dc06c807e47a5d598482445881bf34eeb072814b9fc6e70dd8ff4fb99d2e7e1c256477570e04397034186759d86d496f2fe6
data/README.md CHANGED
@@ -99,6 +99,30 @@ ProfileMapper.map(original)
99
99
  Enjoy!
100
100
 
101
101
  ### Examples:
102
+ **`form_child`:**
103
+
104
+ ```ruby
105
+ {
106
+ passenger_data: {
107
+ traveller_information: {
108
+ passenger: {
109
+ first_name: 'Juanito'
110
+ },
111
+ traveller: {
112
+ surname: 'Perez'
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ class DeepExtraction < HashMap::Base
119
+ from_child :passenger_data, :traveller_information do
120
+ property :firstname, from: [:passenger, :first_name]
121
+ property :lastname, from: [:traveller, :surname]
122
+ end
123
+ end
124
+ ```
125
+
102
126
  **No 'from' key needed:**
103
127
  ```ruby
104
128
  class Clever < HashMap::Base
@@ -77,11 +77,16 @@ module HashMap
77
77
  from_child(key, opts, &block)
78
78
  end
79
79
 
80
- def from_child(key, opts = {}, &block)
81
- flat = _nested(key, opts, &block)
80
+ def from_child(*args, &block)
81
+ options = args.last.is_a?(::Hash) ? args.pop : {}
82
+ key = args
83
+ flat = _nested(key, options, &block)
84
+ keys = Array.wrap(key)
82
85
  flat.each do |attr|
83
- attr[:from].unshift(key)
84
- attr[:from_child] ? attr[:from_child].unshift(key) : attr[:from_child] = [key]
86
+ keys.reverse.each do |k|
87
+ attr[:from].unshift(k)
88
+ attr[:from_child] ? attr[:from_child].unshift(k) : attr[:from_child] = [k]
89
+ end
85
90
  end
86
91
  @attributes += flat
87
92
  end
@@ -1,3 +1,3 @@
1
1
  module HashMap
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Pañach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler