attributes-mapper 0.1.1 → 0.1.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
  SHA256:
3
- metadata.gz: 895e84c722e2e5af0fa6b75967b76ef5c6a550aa62855549e3c037671ef90a36
4
- data.tar.gz: '09914faa96f5420f3a29eac3a634b88185973b3f5022d932c4f50b3da33f4eee'
3
+ metadata.gz: 4de21050a409102a97ed7a57ad9a4e3e407ae1c9236ee12bcf56ba065df09674
4
+ data.tar.gz: aa2537d23e5d13baa679133e50d046992a2a31a2b5abdd3ebad5ec1be5b6e745
5
5
  SHA512:
6
- metadata.gz: 6ca6e1a948e1861ac03d6b77be22c0237ee635c960444cb60f73219e37ce1d65cac1213e76b57fca80d50b595b1bfa3eda48dab6b7361f7410334cea799d090c
7
- data.tar.gz: 2a2e0dae7ca0fdb3db436709361139f4c3af73454df35be8bedce48fd123f5108c7eeb1698186936f243beac1d00f7fc3d483e610d8f655fe8d75c6593329398
6
+ metadata.gz: 804ff034798b639ba1c8cc522df79ecdfafa4403ef4fd320c626db053367d6da846dceecc56449197b20fda7cc6dda1b00fbc91e6cdf230c0804ea0ff757d9ca
7
+ data.tar.gz: 4aadd98e8b6d7e7caaaf4a741eb59231612770a733408d9a98ee064bc561d00d3c50ffc6ba2c723277d64d017f831c4fe5dcf26df8a5c3d2be84a14fc7e426b2
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # AttributesMapper
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/attributes/mapper`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AttributesMapper
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attributes-mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Desmond O'Leary