attributes-mapper 0.1.1 → 0.1.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 +4 -4
- data/README.md +34 -3
- data/lib/attributes-mapper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4de21050a409102a97ed7a57ad9a4e3e407ae1c9236ee12bcf56ba065df09674
|
4
|
+
data.tar.gz: aa2537d23e5d13baa679133e50d046992a2a31a2b5abdd3ebad5ec1be5b6e745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 804ff034798b639ba1c8cc522df79ecdfafa4403ef4fd320c626db053367d6da846dceecc56449197b20fda7cc6dda1b00fbc91e6cdf230c0804ea0ff757d9ca
|
7
|
+
data.tar.gz: 4aadd98e8b6d7e7caaaf4a741eb59231612770a733408d9a98ee064bc561d00d3c50ffc6ba2c723277d64d017f831c4fe5dcf26df8a5c3d2be84a14fc7e426b2
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# AttributesMapper
|
2
2
|
|
3
|
-
|
3
|
+
Builds upon `[json-path-builder](https://github.com/omnitech-solutions/json-path-builder)` to deliver a highly declarative and dynamic mapping of JSON/Hash Attributes
|
4
4
|
|
5
|
-
|
5
|
+
## Console
|
6
|
+
run `irb -r ./dev/setup` for an interactive prompt.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,7 +23,37 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
```ruby
|
27
|
+
class UserAttributesMapper < AttributesMapper::Builder
|
28
|
+
configure do |config|
|
29
|
+
config.required_attributes = %i[name email]
|
30
|
+
config.optional_attributes = %i[age key]
|
31
|
+
config.scopes = { profile: 'user.profile', info: 'user.info' }
|
32
|
+
end
|
33
|
+
|
34
|
+
name { { from: :username, scope: :profile } } # corresponds to path `user.profile.username`
|
35
|
+
email { { from: :email, scope: :profile } } # corresponds to path `user.profile.email`
|
36
|
+
age { { from: :age, scope: :info } } # corresponds to path `user.info.age`
|
37
|
+
key { { from: :key } } # corresponds to path `key`
|
38
|
+
end
|
39
|
+
|
40
|
+
input = { user:
|
41
|
+
{ profile:
|
42
|
+
{
|
43
|
+
username: 'Joe Bloggs',
|
44
|
+
email: 'joe@email.com'
|
45
|
+
},
|
46
|
+
info: {
|
47
|
+
|
48
|
+
age: 23
|
49
|
+
}
|
50
|
+
},
|
51
|
+
key: 'some-value'
|
52
|
+
}
|
53
|
+
|
54
|
+
builder = UserAttributesMapper.new(input).build
|
55
|
+
builder.to_h #=> { name: 'Joe Bloggs', email: 'joe@email.com', age: 23, key: 'some-value' }
|
56
|
+
```
|
26
57
|
|
27
58
|
## Development
|
28
59
|
|