json-path-builder 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/json_path_builder.gemspec +1 -1
- data/lib/{json-path → json-path-builder}/builder.rb +7 -2
- data/lib/{json-path → json-path-builder}/version.rb +1 -1
- data/lib/json_path_builder.rb +11 -0
- data/spec/json-path/builder_spec.rb +19 -40
- metadata +9 -9
- data/lib/json_path.rb +0 -15
- /data/lib/{json-path → json-path-builder}/default_data_wrapper.rb +0 -0
- /data/lib/{json-path → json-path-builder}/path_context.rb +0 -0
- /data/lib/{json-path → json-path-builder}/path_context_collection.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1c880bbfcbc227c4a7296c129f679e7fbf0a966eafce00f1f6d63436bd41079
|
4
|
+
data.tar.gz: 377c9adc964c1ccd383230678a91204b6652ff48e9c90ea9c57bce76a9f78f60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e2155f5ce36ed4386a1bb5a52fed0db103b6d6e047b459272e56bb09e084d5cebbb7aa3e224d2e9452a3149df92bef85c7d1aa302843ad4535b11400b00071
|
7
|
+
data.tar.gz: cece139c00605737eb783e5d9652a729f3038c61d5390f0360db3487fe0691699cca0255daf7ab20ab0ce1952bcb5201821aa3fc9cd9dd325bd9cce2a6348e5b
|
data/json_path_builder.gemspec
CHANGED
@@ -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
|
-
|
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 =
|
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
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rordash'
|
4
|
+
|
5
|
+
require 'json-path-builder/version'
|
6
|
+
require 'json-path-builder/default_data_wrapper'
|
7
|
+
require 'json-path-builder/path_context'
|
8
|
+
require 'json-path-builder/path_context_collection'
|
9
|
+
require 'json-path-builder/builder'
|
10
|
+
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,12 +117,12 @@ files:
|
|
117
117
|
- bin/setup
|
118
118
|
- dev/setup.rb
|
119
119
|
- json_path_builder.gemspec
|
120
|
-
- lib/json-path/builder.rb
|
121
|
-
- lib/json-path/default_data_wrapper.rb
|
122
|
-
- lib/json-path/path_context.rb
|
123
|
-
- lib/json-path/path_context_collection.rb
|
124
|
-
- lib/json-path/version.rb
|
125
|
-
- lib/
|
120
|
+
- lib/json-path-builder/builder.rb
|
121
|
+
- lib/json-path-builder/default_data_wrapper.rb
|
122
|
+
- lib/json-path-builder/path_context.rb
|
123
|
+
- lib/json-path-builder/path_context_collection.rb
|
124
|
+
- lib/json-path-builder/version.rb
|
125
|
+
- lib/json_path_builder.rb
|
126
126
|
- sig/json_path_builder.rbs
|
127
127
|
- spec/coverage_helper.rb
|
128
128
|
- spec/json-path/builder_spec.rb
|
@@ -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.
|
157
|
+
rubygems_version: 3.4.8
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: Declarative mapping JSON/Hash data structures
|
data/lib/json_path.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rordash'
|
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
|
14
|
-
|
15
|
-
module JsonPath; end
|
File without changes
|
File without changes
|
File without changes
|