json-path-builder 0.1.0 → 0.1.1

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: 831f757c0902b11dd95708a1e391810972b552af627d6c174febd631eb559f9e
4
- data.tar.gz: 223b27e91f23f96f215b027a68a903c1b3ea457f422d9609422d54909d0b74c4
3
+ metadata.gz: b33e4496f997d0f1c8346c081daeb8719b0acb59239f072d729cafddd944d3cc
4
+ data.tar.gz: a22fc025b26f31aabdaae954e3637d48c87c98e564b129a41e214f4f3c204681
5
5
  SHA512:
6
- metadata.gz: 7f56570d116634d1afa6723922bfa28a1e7479d322b05d59ce9a7fcde08b17a1e549e130ff614192b79c10490ce9d7120757a0a9e3c586404027416b3076d311
7
- data.tar.gz: 83af8a4de986dd2d3a861969c2a091cc5dab6f06e3319f48e3a95733ce149e39a6bb04311e9264222f7677d5a87ee8fb82aad09474b416251f76940502481ca8
6
+ metadata.gz: 67359a1537323837e1e868f3b848ec3f378e7e6d414997bc6b35a139c5728469bdd2b47eb39d2fa83214698c7a3349765398ed0f26a93e8dd24e5e5a6f207da5
7
+ data.tar.gz: b71066c9c3376bb1e5b6ef03a319f04e790249d7e18a4343619f7ace25f6521b9f4a3c017b828a8fe229bfe91946d624e3965e40d5844aa51d6b49c60313e725
@@ -4,7 +4,7 @@ module JsonPath
4
4
  attr_reader :path_context_collection, :parent_path_context
5
5
 
6
6
  delegate :source_data, :nested_paths, :data_wrapper_class, :reject_from_paths!, to: :path_context_collection,
7
- allow_nil: true
7
+ allow_nil: true
8
8
 
9
9
  def initialize(parent_path_context: nil)
10
10
  @parent_path_context = parent_path_context
@@ -36,6 +36,7 @@ module JsonPath
36
36
 
37
37
  self
38
38
  end
39
+
39
40
  # rubocop:enable Metrics/ParameterLists
40
41
 
41
42
  # rubocop:disable Metrics/ParameterLists
@@ -52,6 +53,7 @@ module JsonPath
52
53
 
53
54
  self
54
55
  end
56
+
55
57
  # rubocop:enable Metrics/ParameterLists
56
58
 
57
59
  def with_source_data(data)
@@ -141,7 +143,7 @@ module JsonPath
141
143
  end
142
144
 
143
145
  def transform_value_with_builder(value, path_context)
144
- builder = PathsBuilder.new(parent_path_context: path_context)
146
+ builder = Builder.new(parent_path_context: path_context)
145
147
  pb = call_proc(path_context.transform, builder, path_context)
146
148
  return pb.build_for(value) if pb&.paths?
147
149
 
@@ -172,6 +174,7 @@ module JsonPath
172
174
 
173
175
  Rordash::HashUtil.deep_symbolize_keys(value)
174
176
  end
177
+
175
178
  # rubocop:enable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity
176
179
 
177
180
  def apply_defaults(data, path_context)
@@ -211,6 +214,7 @@ module JsonPath
211
214
  filled_args.present? ? proc.call(*filled_args) : proc.call
212
215
  end
213
216
  end
217
+
214
218
  # rubocop:enable Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/AbcSize
215
219
 
216
220
  def call_proc_with_extra_args(proc, args, **extra_args)
@@ -228,5 +232,6 @@ module JsonPath
228
232
  path_context_collection.map(&:to)
229
233
  end
230
234
  end
235
+
231
236
  # rubocop:enable Metrics/ClassLength
232
237
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonPathBuilder
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/json_path.rb CHANGED
@@ -2,14 +2,10 @@
2
2
 
3
3
  require 'rordash'
4
4
 
5
- %w[
6
- version
7
- default_data_wrapper
8
- path_context
9
- path_context_collection
10
- builder
11
- ].each do |filename|
12
- require File.expand_path("../json-path/#{filename}", Pathname.new(__FILE__).realpath)
13
- end
5
+ require 'json-path/version'
6
+ require 'json-path/default_data_wrapper'
7
+ require 'json-path/path_context'
8
+ require 'json-path/path_context_collection'
9
+ require 'json-path/builder'
14
10
 
15
11
  module JsonPath; end
@@ -35,6 +35,25 @@ module JsonPath
35
35
  expect(instance.build_for(input)).to eql({ list: list })
36
36
  end
37
37
 
38
+ context 'with complex mapping input' do
39
+ let(:input) { { data: [{ name: 'some-name', region_code: 'AB' }] } }
40
+
41
+ it 'supports building on list attributes' do
42
+ instance.from_each(:data, transform_with_builder: true, transform: proc {|b|
43
+ b.from(:name)
44
+ b.from(:region_code, to: :state)
45
+ })
46
+
47
+ expect(instance.build_for(input)).to eql({ data: [{ name: 'some-name', state: 'AB' }] })
48
+ end
49
+ end
50
+
51
+ it 'handles complex mapping via builder' do
52
+ instance.from_each(:list)
53
+
54
+ expect(instance.build_for(input)).to eql({ list: list })
55
+ end
56
+
38
57
  it 'handles renaming path name' do
39
58
  instance.from(:list, to: :another_list_key)
40
59
 
@@ -124,45 +143,5 @@ module JsonPath
124
143
  end
125
144
  end
126
145
  end
127
-
128
- # describe PathsBuilder::PathContext do
129
- # let(:key) { "some-value" }
130
- # let(:other_key) { "some-other-value" }
131
- # let(:list) { %w[some-list-value-1 some-list-value-2] }
132
- #
133
- # let(:input) { { key: key, other_key: other_key, list: list }.as_json }
134
- # let(:builder) { PathsBuilder.new }
135
- # let(:path_context) { builder.path_context_collection.first }
136
- #
137
- # before(:each) do
138
- # builder.from(:key, to: :another_key, transform: proc { |val| val.upcase })
139
- # builder.with_source_data(input)
140
- # end
141
- #
142
- #
143
- # it 'returns path context instance' do
144
- # expect(path_context).to be_instance_of(described_class)
145
- # end
146
- #
147
- # describe '#wrapped_source_data' do
148
- # subject { path_context.wrapped_source_data }
149
- #
150
- # context 'with custom data class' do
151
- # let(:wrapper_class) { Sharplaunch::PropertyListingDataWrapper }
152
- #
153
- # before(:each) { builder.with_wrapped_data_class(wrapper_class) }
154
- #
155
- # it 'returns custom class' do
156
- # expect(subject).to be_an_instance_of(wrapper_class)
157
- # end
158
- # end
159
- #
160
- # context 'without custom data wrapper class' do
161
- # it 'returns default wrapper instance' do
162
- # expect(subject).to be_instance_of(PathsBuilder::DefaultDataWrapper)
163
- # end
164
- # end
165
- # end
166
- # end
167
146
  end
168
147
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-path-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-02-28 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: activesupport
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.1.6
157
+ rubygems_version: 3.4.8
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Declarative mapping JSON/Hash data structures