CloudSesame 0.1.4 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f00925c20af3319d8ce8f88dc5dff6387d8d68b6
4
- data.tar.gz: f175cc69bb9a53b6a7e3c783c67d482d0361d64b
3
+ metadata.gz: b7aad854d12632f7a254e4d4130381ecf2c1e468
4
+ data.tar.gz: d150f9b6a91d47da8fd83df34b967c78507221bf
5
5
  SHA512:
6
- metadata.gz: 1eed85f4d9436110b17c7e0b842713daaaf5278014fd20f5a8c2e00931392bfb0d5e66b3ee0f796bb4df36f31753497f43353f1b93826247dbb4b0a2c03ff2f6
7
- data.tar.gz: 6d4a8daea2e4edfbecbf33c325022295040a0b73ca8e8c9c11e451a23d1e2b49d728319d542a76fac93a73d1ba7a8872f3b0ce77502611519effc572fcbfd304
6
+ metadata.gz: 1a2374d616b59d412dcc228f51343ce56e0d9686ffc322f272a7ded656976ffeaab5492cd83547feec36619279bea6a97d094f66b8377692f3e509f89122ce2b
7
+ data.tar.gz: 816abf070d875a9d1d2df1e54bd0b1aa23618d09c1bcbf0d4e067c6abb6170667c8889b649066bd5fbe3d1aa4be712ce5251bfc73562fdd9a0f5c4ccac1f2ceb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- CloudSesame (0.1.3)
4
+ CloudSesame (0.1.4)
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.1.4'
3
+ s.version = '0.1.5'
4
4
  s.date = '2016-01-14'
5
5
  s.summary = "AWS CloudSearch Query Interface"
6
6
  s.description = "AWS CloudSearch Query Interface"
data/lib/cloud_sesame.rb CHANGED
@@ -43,6 +43,8 @@ require 'cloud_sesame/query/ast/prefix'
43
43
  require 'cloud_sesame/query/ast/compound_array'
44
44
  require 'cloud_sesame/query/ast/literal'
45
45
  require 'cloud_sesame/query/ast/value'
46
+ require 'cloud_sesame/query/ast/date_value'
47
+ require 'cloud_sesame/query/ast/range_value'
46
48
 
47
49
  # Query Request Nodes
48
50
  # ===============================================
@@ -0,0 +1,21 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ class DateValue < Value
5
+
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def compile
11
+ strip escape @data.strftime('%FT%TZ')
12
+ end
13
+
14
+ def to_s
15
+ compile
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -7,8 +7,9 @@ module CloudSesame
7
7
  attr_reader :value, :options
8
8
 
9
9
  def initialize(field, value, options = {})
10
- @field = field
11
- @value = Value.new(value)
10
+ self.field = field
11
+ self.value = value
12
+
12
13
  @options = options
13
14
  (options[:included] ||= []) << value
14
15
  end
@@ -19,7 +20,7 @@ module CloudSesame
19
20
  end
20
21
 
21
22
  def value=(value)
22
- @value = Value.new(value)
23
+ @value = value.kind_of?(Value) ? value : Value.new(value)
23
24
  end
24
25
 
25
26
  def compile
@@ -0,0 +1,78 @@
1
+ module CloudSesame
2
+ module Query
3
+ module AST
4
+ class RangeValue < Value
5
+
6
+ attr_accessor :lower_bound_included,
7
+ :upper_bound_included
8
+
9
+ def initialize
10
+ @data = [nil, nil]
11
+ end
12
+
13
+ def compile
14
+ strip "#{ lower_bound }#{ lower.compile if lower },#{ upper.compile if upper }#{ upper_bound }"
15
+ end
16
+
17
+ def to_s
18
+ compile
19
+ end
20
+
21
+ def gt(value)
22
+ self.lower = value
23
+ self.lower_bound_included = false
24
+ return self
25
+ end
26
+
27
+ def gte(value)
28
+ self.lower = value
29
+ self.lower_bound_included = true
30
+ return self
31
+ end
32
+
33
+ def lt(value)
34
+ self.upper = value
35
+ self.upper_bound_included = false
36
+ return self
37
+ end
38
+
39
+ def lte(value)
40
+ self.upper = value
41
+ self.upper_bound_included = true
42
+ return self
43
+ end
44
+
45
+ def lower
46
+ data[0]
47
+ end
48
+
49
+ def lower=(value)
50
+ data[0] = to_value(value)
51
+ end
52
+
53
+ def upper
54
+ data[1]
55
+ end
56
+
57
+ def upper=(value)
58
+ data[1] = to_value(value)
59
+ end
60
+
61
+ def lower_bound
62
+ lower && lower_bound_included ? '[' : '{'
63
+ end
64
+
65
+ def upper_bound
66
+ upper && upper_bound_included ? ']' : '}'
67
+ end
68
+
69
+ private
70
+
71
+ def to_value(value)
72
+ value.kind_of?(Value) ? value : Value.new(value)
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -27,11 +27,14 @@ module CloudSesame
27
27
  data.to_s =~ /^\d+(.\d+)?$/
28
28
  end
29
29
 
30
- # "hello" => "'hello'"
31
30
  def escape(data = "")
32
31
  "'#{ data.to_s.gsub(/\'/) { "\\'" } }'"
33
32
  end
34
33
 
34
+ def strip(string)
35
+ string.gsub(/ /, '')
36
+ end
37
+
35
38
  end
36
39
  end
37
40
  end
@@ -3,12 +3,12 @@ module CloudSesame
3
3
  module DSL
4
4
  module LiteralHelper
5
5
 
6
- def d(date_object)
7
- strip date_object.strftime('%FT%TZ')
6
+ def d(date)
7
+ AST::DateValue.new date
8
8
  end
9
9
 
10
- def strip(string)
11
- string.gsub(/ /, '')
10
+ def r
11
+ AST::RangeValue.new
12
12
  end
13
13
 
14
14
  end
@@ -50,14 +50,12 @@ describe CloudSesame do
50
50
  # field :searchable_text, query: { weight: 4 }
51
51
  # end
52
52
  # end
53
-
54
53
  # # Example Query
55
- # # result = Product.cloudsearch.query("shoes")
56
- # # .page(3)
57
- # # .or {
58
- # # tags.not.near "men", "women"
59
- # # }
60
-
54
+ # result = Product.cloudsearch.query("shoes")
55
+ # .or {
56
+ # created_at "[#{ d(Date.today - 3) },}"
57
+ # created_at r.gte(d(Date.today - 3))
58
+ # }
61
59
  # binding.pry
62
60
 
63
61
  end
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chu
@@ -108,6 +108,7 @@ files:
108
108
  - lib/cloud_sesame/domain/context.rb
109
109
  - lib/cloud_sesame/query/ast/and.rb
110
110
  - lib/cloud_sesame/query/ast/compound_array.rb
111
+ - lib/cloud_sesame/query/ast/date_value.rb
111
112
  - lib/cloud_sesame/query/ast/leaf.rb
112
113
  - lib/cloud_sesame/query/ast/literal.rb
113
114
  - lib/cloud_sesame/query/ast/multi_branch.rb
@@ -116,6 +117,7 @@ files:
116
117
  - lib/cloud_sesame/query/ast/not.rb
117
118
  - lib/cloud_sesame/query/ast/or.rb
118
119
  - lib/cloud_sesame/query/ast/prefix.rb
120
+ - lib/cloud_sesame/query/ast/range_value.rb
119
121
  - lib/cloud_sesame/query/ast/root.rb
120
122
  - lib/cloud_sesame/query/ast/single_branch.rb
121
123
  - lib/cloud_sesame/query/ast/single_expression_operator.rb