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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea4ecf6626a9a55c1c9498d10d8e64fd382e046a
4
- data.tar.gz: 848033290c03302400ab3311c216a3cf69c47fee
3
+ metadata.gz: 2156e94f555e526308eabb17c416c12883081b18
4
+ data.tar.gz: 210369d1ba7954ad0132d189e8c0976845ca294a
5
5
  SHA512:
6
- metadata.gz: 2483e48b85610b202bc5d2cf1d755608eea89d0629417e1bf148f088a8f25e7924ae8129c69ce428ba9c223c5c161e8798c8208e73c66c25cebc10fe6bfb6c94
7
- data.tar.gz: d68a784620b91a8b1f9bb8009ed849eacee1621ed4dc0711a2ef9fc5c59c41f40c1e1554bd44e36c089835fffc39bf5be6ab048f2a340e60b836b808041844b1
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 hash_key_operators.include? key
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)]
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'msfl_visitors'
3
- s.version = '0.1.0.rc0'
4
- s.date = '2015-05-06'
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) { ->(comp_node) { MSFLVisitors::Nodes::Filter.new [ comp_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 1000 }
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: 1000 } }
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 { -> (filter) { described_class.new.parse filter } }
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
- let(:implicit_equality_filter) { { value: 1000 } }
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
- let(:explicit_gte_filter) { { value: { gte: 1000 } } }
92
+ describe "parsing a lte filter" do
32
93
 
33
- let(:containment_filter) { { value: { in: containment_values } } }
94
+ let(:filter) { { value: { lte: one_thousand } } }
34
95
 
35
- let(:containment_values) { MSFL::Types::Set.new [50, 250, 20000] }
96
+ let(:lte_node) { MSFLVisitors::Nodes::LessThanEqual.new left, right }
36
97
 
37
- it "handles implicit equality comparisons" do
38
- expect(subject.call(implicit_equality_filter)).to eq expected_node.call(MSFLVisitors::Nodes::Equal.new(left, right))
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
- it "handles explicit comparisons" do
42
- comparison_node = MSFLVisitors::Nodes::GreaterThanEqual.new left, right
43
- expect(subject.call(explicit_gte_filter)).to eq expected_node.call(comparison_node)
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
- # { value: { in: [50, 250, 20000] } }
47
- #
48
- # => Nodes::Containment.new(Nodes::Field.new(:value),
49
- # Nodes::Set::Set.new([
50
- # Nodes::Number.new(50),
51
- # Nodes::Number.new(250),
52
- # Nodes::Number.new(20000)]))
53
- it "handles containments" do
54
- contained_nodes = containment_values.map { |value| MSFLVisitors::Nodes::Number.new(value) }
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(:bad_filter) { { foo: Object.new } }
135
+ let(:filter) { { foo: Object.new } }
63
136
 
64
137
  it "raises an ArgumentError" do
65
- expect { subject.call(bad_filter) }.to raise_error ArgumentError
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.rc0
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-06 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msfl