msfl 1.1.4 → 1.1.5
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/lib/msfl/converters/operator.rb +9 -3
- data/msfl.gemspec +1 -1
- data/spec/msfl/converters/operator_spec.rb +51 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 177a30d02e7d96f90d3a86fd31804f7dcfacae54
|
4
|
+
data.tar.gz: 5e6ddff54fcc8f8380e51967a81b6a8b48931ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c76fe997453a7ad780a7ebeb6f91558777075b5f2085c6aa2c2b0a4282d10c91eec1e18fa7267c0c058ddb9eeb6f129b446352bacaf55565aa60ea4e46af76
|
7
|
+
data.tar.gz: 1329571a071f77f574acd92223f79d7fad3dfbf94a63a4d88eca1acc782a354a336ae20120f73a8dc68b92a54721aa4529d180e9e0ce51d63583e9fb9083d79a
|
@@ -37,15 +37,21 @@ module MSFL
|
|
37
37
|
|
38
38
|
# { year: { start: 2001, end: 2005 } }
|
39
39
|
# => { year: { between: { start: 2001, end: 2015 } } }
|
40
|
-
def implicit_between_to_explicit_recursively(obj)
|
41
|
-
if
|
40
|
+
def implicit_between_to_explicit_recursively(obj, parent_key = nil)
|
41
|
+
if parent_key == :between
|
42
|
+
# The immediately ancestor key is :between, so don't do anything special with :start and :end
|
43
|
+
result = Hash.new
|
44
|
+
obj.each do |k, v|
|
45
|
+
result[k] = implicit_between_to_explicit_recursively(v)
|
46
|
+
end
|
47
|
+
elsif obj.is_a? Hash
|
42
48
|
# if the hash has two keys :start and :end, nest it inside a between and recurse on the values
|
43
49
|
if obj.has_key?(:start) && obj.has_key?(:end)
|
44
50
|
result = { between: { start: implicit_between_to_explicit_recursively(obj[:start]), end: implicit_between_to_explicit_recursively(obj[:end]) } }
|
45
51
|
else
|
46
52
|
result = Hash.new
|
47
53
|
obj.each do |k, v|
|
48
|
-
result[k] = implicit_between_to_explicit_recursively(v)
|
54
|
+
result[k] = implicit_between_to_explicit_recursively(v, k)
|
49
55
|
end
|
50
56
|
end
|
51
57
|
elsif obj.is_a? Types::Set
|
data/msfl.gemspec
CHANGED
@@ -77,6 +77,46 @@ describe "MSFL::Converters::Operator" do
|
|
77
77
|
|
78
78
|
subject
|
79
79
|
end
|
80
|
+
|
81
|
+
context "when the object to be converted is { investor_id: { between: { start: 10, end: 50 } } }" do
|
82
|
+
|
83
|
+
let(:test_instance) { MSFL::Converters::Operator.new }
|
84
|
+
|
85
|
+
let(:obj) { { investor_id: { between: { start: 10, end: 50 } } } }
|
86
|
+
|
87
|
+
let(:expected) do
|
88
|
+
{ and: MSFL::Types::Set.new([
|
89
|
+
{ investor_id: { gte: 10 } },
|
90
|
+
{ investor_id: { lte: 50 } }
|
91
|
+
])}
|
92
|
+
end
|
93
|
+
|
94
|
+
let(:conversions_to_run) { nil }
|
95
|
+
|
96
|
+
it "is the the ANDed gte / lte equivalent expression" do
|
97
|
+
expect(subject).to eq expected
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when the object to be converted is { investor_id: { start: 10, end: 50 } }" do
|
102
|
+
|
103
|
+
let(:test_instance) { MSFL::Converters::Operator.new }
|
104
|
+
|
105
|
+
let(:obj) { { investor_id: { start: 10, end: 50 } } }
|
106
|
+
|
107
|
+
let(:expected) do
|
108
|
+
{ and: MSFL::Types::Set.new([
|
109
|
+
{ investor_id: { gte: 10 } },
|
110
|
+
{ investor_id: { lte: 50 } }
|
111
|
+
])}
|
112
|
+
end
|
113
|
+
|
114
|
+
let(:conversions_to_run) { nil }
|
115
|
+
|
116
|
+
it "is the the ANDed gte / lte equivalent expression" do
|
117
|
+
expect(subject).to eq expected
|
118
|
+
end
|
119
|
+
end
|
80
120
|
end
|
81
121
|
|
82
122
|
|
@@ -201,6 +241,17 @@ describe "MSFL::Converters::Operator" do
|
|
201
241
|
expect(subject).to eq expected
|
202
242
|
end
|
203
243
|
end
|
244
|
+
|
245
|
+
context "when there is an explicit BETWEEN" do
|
246
|
+
|
247
|
+
let(:arg) { { investor_id: { between: { start: 10, end: 50 } } } }
|
248
|
+
|
249
|
+
let(:expected) { arg }
|
250
|
+
|
251
|
+
it "is unchanged" do
|
252
|
+
expect(subject).to eq expected
|
253
|
+
end
|
254
|
+
end
|
204
255
|
end
|
205
256
|
end
|
206
257
|
|