msfl_visitors 0.1.0.rc0 → 0.1.0.rc1
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_visitors/parsers/msfl_parser.rb +7 -2
- data/msfl_visitors.gemspec +2 -2
- data/spec/parsers/msfl_parser_spec.rb +100 -27
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2156e94f555e526308eabb17c416c12883081b18
|
4
|
+
data.tar.gz: 210369d1ba7954ad0132d189e8c0976845ca294a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88dbf7a0b57600f139098d0a334f25d3b3404b9ebf8299d6fb97cda1e6c15db510f34fb62c0f4b2f098bb349dd1071b7ecef6e9b1ab9c2d71ffe71e3e729740f
|
7
|
+
data.tar.gz: 11c609cbf7a04bd5a4fd2248e49b956384af7d758399d2ad1a3c9601fd192b9ef8062715625ff2064c1149be82a9de40fefbd1279ee031bc86aa396630f74279
|
@@ -2,12 +2,17 @@ require 'msfl'
|
|
2
2
|
module MSFLVisitors
|
3
3
|
module Parsers
|
4
4
|
class MSFLParser
|
5
|
-
include MSFL::Validators::Definitions::HashKey
|
5
|
+
# include MSFL::Validators::Definitions::HashKey
|
6
6
|
|
7
7
|
OPERATORS_TO_NODE_CLASS = {
|
8
|
+
and: Nodes::And,
|
8
9
|
gt: Nodes::GreaterThan,
|
9
10
|
gte: Nodes::GreaterThanEqual,
|
11
|
+
eq: Nodes::Equal,
|
12
|
+
lt: Nodes::LessThan,
|
13
|
+
lte: Nodes::LessThanEqual,
|
10
14
|
in: Nodes::Containment,
|
15
|
+
|
11
16
|
}
|
12
17
|
|
13
18
|
def parse(obj, lhs = false)
|
@@ -58,7 +63,7 @@ module MSFLVisitors
|
|
58
63
|
end
|
59
64
|
|
60
65
|
def hash_dispatch(key, value, lhs = false)
|
61
|
-
if
|
66
|
+
if OPERATORS_TO_NODE_CLASS.include? key
|
62
67
|
# Detect the node type, forward the lhs if it was passed in (essentially when the operator is a binary op)
|
63
68
|
args = [lhs, parse(value)] if lhs
|
64
69
|
args ||= [parse(value)]
|
data/msfl_visitors.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'msfl_visitors'
|
3
|
-
s.version = '0.1.0.
|
4
|
-
s.date = '2015-05-
|
3
|
+
s.version = '0.1.0.rc1'
|
4
|
+
s.date = '2015-05-08'
|
5
5
|
s.summary = "Convert MSFL to other forms"
|
6
6
|
s.description = "Visitor pattern approach to converting MSFL to other forms."
|
7
7
|
s.authors = ["Courtland Caldwell"]
|
@@ -3,17 +3,19 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe MSFLVisitors::Parsers::MSFLParser do
|
5
5
|
|
6
|
-
let(:expected_node) { ->(
|
6
|
+
let(:expected_node) { ->(wrapped_node) { MSFLVisitors::Nodes::Filter.new [ wrapped_node ] } }
|
7
7
|
|
8
8
|
let(:left) { MSFLVisitors::Nodes::Field.new :value }
|
9
9
|
|
10
|
-
let(:right) { MSFLVisitors::Nodes::Number.new
|
10
|
+
let(:right) { MSFLVisitors::Nodes::Number.new one_thousand }
|
11
|
+
|
12
|
+
let(:one_thousand) { 1000 }
|
11
13
|
|
12
14
|
describe "parsing a trivial filter" do
|
13
15
|
|
14
16
|
subject { described_class.new.parse msfl }
|
15
17
|
|
16
|
-
let(:msfl) { { value:
|
18
|
+
let(:msfl) { { value: one_thousand } }
|
17
19
|
|
18
20
|
it "is the expected node" do
|
19
21
|
expect(subject).to eq expected_node.call(MSFLVisitors::Nodes::Equal.new(left, right))
|
@@ -24,45 +26,116 @@ describe MSFLVisitors::Parsers::MSFLParser do
|
|
24
26
|
|
25
27
|
context "when parsing a filter" do
|
26
28
|
|
27
|
-
subject {
|
29
|
+
subject { described_class.new.parse(filter) }
|
30
|
+
|
31
|
+
let(:set_of_values) { MSFL::Types::Set.new [50, 250, 20000] }
|
32
|
+
|
33
|
+
let(:set_of_nodes) { set_of_values.map { |value| MSFLVisitors::Nodes::Number.new value } }
|
34
|
+
|
35
|
+
let(:set_node) { MSFLVisitors::Nodes::Set::Set.new set_of_nodes }
|
36
|
+
|
37
|
+
describe "parsing implicit equality" do
|
38
|
+
|
39
|
+
let(:filter) { { value: one_thousand } }
|
40
|
+
|
41
|
+
it "is the expected Equal node" do
|
42
|
+
expect(subject).to eq expected_node.call(MSFLVisitors::Nodes::Equal.new(left, right))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "parsing explict comparisons" do
|
47
|
+
|
48
|
+
describe "parsing a gt filter" do
|
49
|
+
|
50
|
+
let(:filter) { { value: { gt: one_thousand } } }
|
51
|
+
|
52
|
+
let(:gt_node) { MSFLVisitors::Nodes::GreaterThan.new left, right }
|
53
|
+
|
54
|
+
it "is the expected GreaterThan node" do
|
55
|
+
expect(subject).to eq expected_node.call(gt_node)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "parsing a gte filter" do
|
60
|
+
|
61
|
+
let(:filter) { { value: { gte: one_thousand } } }
|
62
|
+
|
63
|
+
let(:gte_node) { MSFLVisitors::Nodes::GreaterThanEqual.new left, right }
|
64
|
+
|
65
|
+
it "is the expected GreaterThanEqual node" do
|
66
|
+
expect(subject).to eq expected_node.call(gte_node)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "parsing a eq filter" do
|
71
|
+
|
72
|
+
let(:filter) { { value: { eq: one_thousand } } }
|
73
|
+
|
74
|
+
let(:eq_node) { MSFLVisitors::Nodes::Equal.new left, right }
|
75
|
+
|
76
|
+
it "is the expected Equal node" do
|
77
|
+
expect(subject).to eq expected_node.call(eq_node)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "parsing a lt filter" do
|
82
|
+
|
83
|
+
let(:filter) { { value: { lt: one_thousand } } }
|
28
84
|
|
29
|
-
|
85
|
+
let(:lt_node) { MSFLVisitors::Nodes::LessThan.new left, right }
|
86
|
+
|
87
|
+
it "is the expected LessThan node" do
|
88
|
+
expect(subject).to eq expected_node.call(lt_node)
|
89
|
+
end
|
90
|
+
end
|
30
91
|
|
31
|
-
|
92
|
+
describe "parsing a lte filter" do
|
32
93
|
|
33
|
-
|
94
|
+
let(:filter) { { value: { lte: one_thousand } } }
|
34
95
|
|
35
|
-
|
96
|
+
let(:lte_node) { MSFLVisitors::Nodes::LessThanEqual.new left, right }
|
36
97
|
|
37
|
-
|
38
|
-
|
98
|
+
it "is the expected LessThanEqual node" do
|
99
|
+
expect(subject).to eq expected_node.call(lte_node)
|
100
|
+
end
|
101
|
+
end
|
39
102
|
end
|
40
103
|
|
41
|
-
|
42
|
-
|
43
|
-
|
104
|
+
describe "parsing containment" do
|
105
|
+
|
106
|
+
let(:filter) { { value: { in: set_of_values } } }
|
107
|
+
|
108
|
+
let(:containment_node) { MSFLVisitors::Nodes::Containment.new left, set_node }
|
109
|
+
|
110
|
+
# { value: { in: [50, 250, 20000] } }
|
111
|
+
#
|
112
|
+
# => Nodes::Containment.new(Nodes::Field.new(:value),
|
113
|
+
# Nodes::Set::Set.new([
|
114
|
+
# Nodes::Number.new(50),
|
115
|
+
# Nodes::Number.new(250),
|
116
|
+
# Nodes::Number.new(20000)]))
|
117
|
+
it "is the expected Containment node" do
|
118
|
+
expect(subject).to eq expected_node.call(containment_node)
|
119
|
+
end
|
44
120
|
end
|
45
121
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
set_node = MSFLVisitors::Nodes::Set::Set.new(contained_nodes)
|
56
|
-
containment_node = MSFLVisitors::Nodes::Containment.new left, set_node
|
57
|
-
expect(subject.call(containment_filter)).to eq expected_node.call(containment_node)
|
122
|
+
describe "parsing an and filter" do
|
123
|
+
|
124
|
+
let(:filter) { { and: set_of_values } }
|
125
|
+
|
126
|
+
let(:and_node) { MSFLVisitors::Nodes::And.new set_node }
|
127
|
+
|
128
|
+
it "is the expected And node" do
|
129
|
+
expect(subject).to eq expected_node.call(and_node)
|
130
|
+
end
|
58
131
|
end
|
59
132
|
|
60
133
|
context "when the filter contains an unsupported type" do
|
61
134
|
|
62
|
-
let(:
|
135
|
+
let(:filter) { { foo: Object.new } }
|
63
136
|
|
64
137
|
it "raises an ArgumentError" do
|
65
|
-
expect { subject
|
138
|
+
expect { subject }.to raise_error ArgumentError
|
66
139
|
end
|
67
140
|
end
|
68
141
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msfl_visitors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msfl
|