CloudSesame 0.2.4 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee2f110af5801dc881dfc3066166ad65481bc9db
4
- data.tar.gz: 981fc6f70346fb0f0cc89842d34c0ab27a0bf918
3
+ metadata.gz: 3459d29078ee48b4320364769b91bbe66f7fbece
4
+ data.tar.gz: e77c9b2917e402329afa7206512d51f77fe973aa
5
5
  SHA512:
6
- metadata.gz: 52fbacfb8507b86e22fb01dd10440249ef38ba4305ce83c2aaa348b5f1d447af093b1f5f0184868e22f07e583f6552108a5792ea749520171def79496380b61a
7
- data.tar.gz: 082924caf18ca846469bf1e9957a0dbb27b192c2445db8f001724e9137b74cbef7aa323a3ce5def4d4e954f4352c9c099342f1e5e49e792183cafcf2f19b7e97
6
+ metadata.gz: 3d8586b977026307c6ef5027cf98f76c9fea091d75e99bfad83a67d446f53b8b469b92c56537b38e6eec0ca8fd81f8c07ab644c668fcc45e83159f6bdcf6b653
7
+ data.tar.gz: 9f66a716cf04f1713dca9a59fd6ef633c5d71432661d78af41110e164d51527721d1bb09d63bd464a25c00116e2308de9647a644c301e1fb22ba502b5b10caea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- CloudSesame (0.2.4)
4
+ CloudSesame (0.2.5)
5
5
  aws-sdk (~> 2)
6
6
 
7
7
  GEM
data/cloud_sesame.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'CloudSesame'
3
- s.version = '0.2.4'
3
+ s.version = '0.2.5'
4
4
  s.date = '2016-01-14'
5
5
  s.summary = "AWS CloudSearch Query DSL"
6
6
  s.description = "AWS CloudSearch Query DSL"
@@ -9,17 +9,13 @@ module CloudSesame
9
9
  def initialize(context, options = {}, &block)
10
10
  @context = context
11
11
  @options = options
12
- evaluate &block if block_given?
12
+ instance_eval &block if block_given?
13
13
  end
14
14
 
15
15
  def boost
16
16
  " boost=#{ options[:boost] }" if options[:boost]
17
17
  end
18
18
 
19
- def evaluate(&block)
20
- instance_eval &block
21
- end
22
-
23
19
  end
24
20
  end
25
21
  end
@@ -10,11 +10,11 @@ module CloudSesame
10
10
  attr_accessor :child
11
11
 
12
12
  def is_for(field, field_options)
13
- child.is_for field, field_options
13
+ child.is_for field, field_options if child
14
14
  end
15
15
 
16
16
  def is_excluded
17
- child.is_excluded
17
+ child.is_excluded if child
18
18
  end
19
19
 
20
20
  def <<(object)
@@ -8,7 +8,7 @@ module CloudSesame
8
8
  def not(options = {}, &block)
9
9
  raise missing_block unless block_given?
10
10
  node = AST::Not.new(dsl_context, options)
11
- orphan_node.evaluate &block
11
+ orphan_node.instance_eval &block
12
12
  node << orphan_node
13
13
  dsl_scope << node
14
14
  dsl_return node
@@ -8,7 +8,20 @@ module CloudSesame
8
8
  end
9
9
 
10
10
  def root
11
- @root ||= CloudSesame::Query::AST::Root.new context
11
+ @root ||= create_root_with_default_values
12
+ end
13
+
14
+ private
15
+
16
+ def create_root_with_default_values
17
+ root = CloudSesame::Query::AST::Root.new context
18
+ context[:fields].each do |field, options|
19
+ if options && (block = options[:default])
20
+ value = root.instance_exec &block
21
+ root << AST::Literal.new(field, value, options)
22
+ end
23
+ end if context[:fields]
24
+ root
12
25
  end
13
26
 
14
27
  end
@@ -0,0 +1,17 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ describe And do
5
+
6
+ it 'should be a type of operator' do
7
+ expect(And.ancestors).to include(MultiExpressionOperator)
8
+ end
9
+
10
+ it 'should have symbol :and' do
11
+ expect(And::SYMBOL).to eq :and
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ describe BlockChainingRelation do
5
+ let(:context) { {} }
6
+ let(:dsl_scope) { OpenStruct.new context: context }
7
+ let(:dsl_return) { OpenStruct.new context: context }
8
+ let(:orphan_node) { OpenStruct.new }
9
+ subject { BlockChainingRelation.new dsl_scope, dsl_return, orphan_node }
10
+
11
+ describe '#dsl_context' do
12
+ it 'should return dsl_scope context' do
13
+ expect(subject.dsl_scope).to receive(:context)
14
+ subject.dsl_context
15
+ end
16
+ end
17
+
18
+ describe '#dsl_return' do
19
+ context 'when dsl return is a root node' do
20
+ let(:dsl_scope) { Root.new(context) }
21
+ it 'should return the root' do
22
+ expect(subject.dsl_return).to eq dsl_return
23
+ end
24
+ end
25
+ context 'when dsl return is not a root node' do
26
+ context 'and node is passed in' do
27
+ let(:node) { OpenStruct.new }
28
+ it 'should return the node' do
29
+ expect(subject.dsl_return node).to eq node
30
+ end
31
+ end
32
+ context 'and node is not passed in' do
33
+ it 'should return the node' do
34
+ expect(subject.dsl_return).to eq dsl_return
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,76 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ describe MultiExpressionOperator do
5
+
6
+ let(:context) { {} }
7
+ let(:options) { {} }
8
+ let(:block) { Proc.new {} }
9
+
10
+ subject { MultiExpressionOperator.new(context, options, &block) }
11
+
12
+ it 'should be a type of operator' do
13
+ expect(MultiExpressionOperator.ancestors).to include(Operator)
14
+ end
15
+
16
+ describe '#children' do
17
+ it 'should be empty by default' do
18
+ expect(subject.children).to be_empty
19
+ end
20
+ it 'should be an Field Array' do
21
+ expect(subject.children).to be_a AST::FieldArray
22
+ end
23
+ end
24
+
25
+ describe '#compile' do
26
+ context 'when theres children' do
27
+ let(:child) { OpenStruct.new(compile: "compiled") }
28
+ before { subject.children << child }
29
+
30
+ it 'should compile to children' do
31
+ expect(subject.children).to receive(:compile)
32
+ subject.compile
33
+ end
34
+
35
+ context 'and boost options is given' do
36
+ before { subject.options[:boost] = 2 }
37
+ it 'should return compiled string with boost' do
38
+ expect(subject.compile).to eq "( boost=2 compiled)"
39
+ end
40
+ end
41
+ context 'and boost options is not given' do
42
+ it 'should return compiled string with boost' do
43
+ expect(subject.compile).to eq "( compiled)"
44
+ end
45
+ end
46
+ end
47
+ context 'when theres no children' do
48
+ it 'should return nothing' do
49
+ expect(subject.compile).to eq nil
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '#<<' do
55
+ it 'should push object into the children' do
56
+ object = :hello
57
+ expect(subject.children).to receive(:<<).with(object)
58
+ subject << object
59
+ end
60
+ end
61
+
62
+ describe '#is_excluded' do
63
+ let(:child) { OpenStruct.new(is_excluded: nil) }
64
+ before { subject.children << child.dup << child.dup << child.dup }
65
+ it 'should broadcast down this method to it\'s children' do
66
+ subject.children.each do |child|
67
+ expect(child).to receive(:is_excluded)
68
+ end
69
+ subject.is_excluded
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ module CloudSesame
4
+ module Query
5
+ module AST
6
+ describe Operator do
7
+ let(:context) {{}}
8
+ let(:options) {{}}
9
+ let(:block) { Proc.new {} }
10
+ subject { Operator.new(context, options, &block) }
11
+
12
+ describe '#initialize' do
13
+ context 'given a block' do
14
+ let(:block) { Proc.new { context[:name] = :test } }
15
+ it 'should evalute the block' do
16
+ expect(subject.context[:name]).to eq :test
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#boost' do
22
+ context 'given boost option' do
23
+ let(:options) {{ boost: 2 }}
24
+ it 'should return an compiled boost value' do
25
+ expect(subject.boost).to eq " boost=2"
26
+ end
27
+ end
28
+ context 'given no boost option' do
29
+ it 'should return nothing' do
30
+ expect(subject.boost).to eq nil
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ describe Or do
5
+
6
+ it 'should be a type of operator' do
7
+ expect(Or.ancestors).to include(MultiExpressionOperator)
8
+ end
9
+
10
+ it 'should have symbol :or' do
11
+ expect(Or::SYMBOL).to eq :or
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
File without changes
@@ -0,0 +1,84 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ describe SingleExpressionOperator do
5
+
6
+ let(:context) { {} }
7
+ let(:options) { {} }
8
+ let(:block) { Proc.new {} }
9
+
10
+ subject { SingleExpressionOperator.new(context, options, &block) }
11
+
12
+ it 'should be a type of operator' do
13
+ expect(MultiExpressionOperator.ancestors).to include(Operator)
14
+ end
15
+
16
+ describe '#child' do
17
+ it 'should be nil by default' do
18
+ expect(subject.child).to be_nil
19
+ end
20
+ end
21
+
22
+ describe '#is_for' do
23
+ it 'should forward the field and field options to it\'s child' do
24
+ subject.child = OpenStruct.new is_for: ""
25
+ expect(subject.child).to receive(:is_for).with(:test, :options)
26
+ subject.is_for :test, :options
27
+ end
28
+ end
29
+
30
+ describe '#is_excluded' do
31
+ context 'when child exist' do
32
+ it 'should call #is_excluded on it\'s child' do
33
+ subject.child = OpenStruct.new is_excluded: ""
34
+ expect(subject.child).to receive(:is_excluded)
35
+ subject.is_excluded
36
+ end
37
+ end
38
+ context 'when child not exist' do
39
+ it 'should call #is_excluded on it\'s child' do
40
+ expect(subject.child).to_not receive(:is_excluded)
41
+ subject.is_excluded
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#<<' do
47
+ it 'should set the object as child' do
48
+ child = OpenStruct.new()
49
+ expect { subject << child }.to change{ subject.child }.from(nil).to(child)
50
+ end
51
+ end
52
+
53
+ describe '#compile' do
54
+ before {
55
+ subject.child = OpenStruct.new compile: ""
56
+ allow(subject.child).to receive(:compile)
57
+ }
58
+ it 'should compile it\'s child and detailed set to false' do
59
+ expect(subject.child).to receive(:compile).with(SingleExpressionOperator::DETAILED)
60
+ subject.compile
61
+ end
62
+ context 'when theres boost options' do
63
+ it 'should include boost value in the compiled value' do
64
+ subject.options[:boost] = 1
65
+ expect(subject.compile).to include("boost=1")
66
+ end
67
+ end
68
+ context 'when theres no boost options' do
69
+ it 'should not include boost value in the compiled value' do
70
+ expect(subject.compile).to_not include("boost=")
71
+ end
72
+ end
73
+ context 'when theres a symbol' do
74
+ before { SingleExpressionOperator::SYMBOL = "test_symbol"}
75
+ it 'should include the symbol in the compiled value' do
76
+ expect(subject.compile).to include "(test_symbol"
77
+ end
78
+ end
79
+ end
80
+
81
+ end
82
+ end
83
+ end
84
+ end
@@ -36,13 +36,6 @@ module CloudSesame
36
36
  expect(node_class).to receive(:new).and_call_original
37
37
  subject.and.not {}
38
38
  end
39
- it 'should create a operator node with the block passed to not' do
40
- proc = -> { }
41
- expect_any_instance_of(AST::And).to receive(:evaluate) { |context, options, &block|
42
- expect(block).to eq(proc)
43
- }
44
- subject.and.not &proc
45
- end
46
39
  it 'should have the operator node as child' do
47
40
  subject.and.not {}
48
41
  expect(subject.request.filter_query.root.children[0].child ).to be_kind_of(AST::And)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CloudSesame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu
@@ -156,6 +156,13 @@ files:
156
156
  - spec/abstract_object_spec.rb
157
157
  - spec/cloud_sesame/domain/base_spec.rb
158
158
  - spec/cloud_sesame/domain/context_spec.rb
159
+ - spec/cloud_sesame/query/ast/and_spec.rb
160
+ - spec/cloud_sesame/query/ast/block_chaining_relation_spec.rb
161
+ - spec/cloud_sesame/query/ast/multi_expression_operator_spec.rb
162
+ - spec/cloud_sesame/query/ast/operator_spec.rb
163
+ - spec/cloud_sesame/query/ast/or_spec.rb
164
+ - spec/cloud_sesame/query/ast/root_spec.rb
165
+ - spec/cloud_sesame/query/ast/single_expression_operator_spec.rb
159
166
  - spec/cloud_sesame/query/dsl/base_spec.rb
160
167
  - spec/cloud_sesame/query/dsl/block_chaining_methods_spec.rb
161
168
  - spec/cloud_sesame/query/dsl/block_methods_spec.rb
@@ -202,6 +209,13 @@ test_files:
202
209
  - spec/abstract_object_spec.rb
203
210
  - spec/cloud_sesame/domain/base_spec.rb
204
211
  - spec/cloud_sesame/domain/context_spec.rb
212
+ - spec/cloud_sesame/query/ast/and_spec.rb
213
+ - spec/cloud_sesame/query/ast/block_chaining_relation_spec.rb
214
+ - spec/cloud_sesame/query/ast/multi_expression_operator_spec.rb
215
+ - spec/cloud_sesame/query/ast/operator_spec.rb
216
+ - spec/cloud_sesame/query/ast/or_spec.rb
217
+ - spec/cloud_sesame/query/ast/root_spec.rb
218
+ - spec/cloud_sesame/query/ast/single_expression_operator_spec.rb
205
219
  - spec/cloud_sesame/query/dsl/base_spec.rb
206
220
  - spec/cloud_sesame/query/dsl/block_chaining_methods_spec.rb
207
221
  - spec/cloud_sesame/query/dsl/block_methods_spec.rb