attributes-mapper 0.1.1 → 0.1.4

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: 895e84c722e2e5af0fa6b75967b76ef5c6a550aa62855549e3c037671ef90a36
4
- data.tar.gz: '09914faa96f5420f3a29eac3a634b88185973b3f5022d932c4f50b3da33f4eee'
3
+ metadata.gz: b3f7da65f2ff2b70efa82e9d72635050aeddd9e23e16c7ce2e513111e25c5ff9
4
+ data.tar.gz: d6bd2568a29650daecc172f0eaca1ca1d2270c879e47630275e8b606d08a69e5
5
5
  SHA512:
6
- metadata.gz: 6ca6e1a948e1861ac03d6b77be22c0237ee635c960444cb60f73219e37ce1d65cac1213e76b57fca80d50b595b1bfa3eda48dab6b7361f7410334cea799d090c
7
- data.tar.gz: 2a2e0dae7ca0fdb3db436709361139f4c3af73454df35be8bedce48fd123f5108c7eeb1698186936f243beac1d00f7fc3d483e610d8f655fe8d75c6593329398
6
+ metadata.gz: 0e9c2757c99792f0509d48c7bc77852c146f5d2de81ce4ff3601b368f53f5f61800d1a8890260b4f896079203da844c5c84361e33d6a843c4b85f118010aec4a
7
+ data.tar.gz: 2b6f2a6eff2c7b8a3b824c35f624ff8448687ce15884611d9630a2f0b385271217470343e792c8cec0490b6e7dc72e4fdafacf98a4cbceb3e1ef83610fbd4f44
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
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.metadata["source_code_uri"] = gem.homepage
23
23
  gem.metadata["changelog_uri"] = "#{gem.homepage}/CHANGELOG.md"
24
24
 
25
- gem.add_runtime_dependency 'json-path-builder', '~> 0.1.0'
25
+ gem.add_runtime_dependency 'json-path-builder', '~> 0.1.7'
26
26
  gem.add_runtime_dependency 'rordash', '~> 0.1.2'
27
27
 
28
28
  gem.add_development_dependency("codecov", "~> 0.6.0")
data/dev/setup.rb CHANGED
@@ -12,6 +12,6 @@ require 'active_support/core_ext/enumerable'
12
12
  require 'active_support/configurable'
13
13
  require 'rudash'
14
14
 
15
- %w[../../lib/attributes_mapper ../../spec/spec_helper].each do |rel_path|
15
+ %w[../../lib/attributes-mapper ../../spec/spec_helper].each do |rel_path|
16
16
  require File.expand_path(rel_path, Pathname.new(__FILE__).realpath)
17
17
  end
@@ -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.4"
5
5
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rordash'
4
+ require 'json-path-builder'
5
+
6
+ require 'attributes-mapper/version'
7
+ require 'attributes-mapper/configuration'
8
+ require 'attributes-mapper/has_attributes'
9
+ require 'attributes-mapper/builder'
10
+
11
+ module AttributesMapper; end
metadata CHANGED
@@ -1,14 +1,14 @@
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Desmond O'Leary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-03 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-path-builder
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.1.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.1.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rordash
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -117,16 +117,16 @@ files:
117
117
  - bin/rubocop
118
118
  - bin/setup
119
119
  - dev/setup.rb
120
+ - lib/attributes-mapper.rb
120
121
  - lib/attributes-mapper/builder.rb
121
122
  - lib/attributes-mapper/configuration.rb
122
123
  - lib/attributes-mapper/has_attributes.rb
123
124
  - lib/attributes-mapper/version.rb
124
- - lib/attributes_mapper.rb
125
125
  - sig/attributes/mapper.rbs
126
126
  - spec/attributes-mapper/builder_spec.rb
127
127
  - spec/attributes-mapper/configuration_spec.rb
128
128
  - spec/attributes-mapper/has_attributes_spec.rb
129
- - spec/attributes_mapper_spec.rb
129
+ - spec/attributes-mapper_spec.rb
130
130
  - spec/coverage_helper.rb
131
131
  - spec/spec_helper.rb
132
132
  homepage: https://github.com/omnitech-solutions/attributes-mapper
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubygems_version: 3.1.6
155
+ rubygems_version: 3.4.8
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Declarative attributes mapping
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rordash'
4
- require 'json-path/builder'
5
- require 'json-path/default_data_wrapper'
6
- require 'json-path/path_context'
7
- require 'json-path/path_context_collection'
8
-
9
- %w[
10
- version
11
- configuration
12
- has_attributes
13
- builder
14
- ].each do |filename|
15
- require File.expand_path("../attributes-mapper/#{filename}", Pathname.new(__FILE__).realpath)
16
- end
17
-
18
- module AttributesMapper; end