querylicious 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d647b4ba6c6965abc5ceae3ad74e1d98f236d7fd
4
- data.tar.gz: c2d9974ae1a66561d63eca13d08a521734b878c9
3
+ metadata.gz: e1f4d432e05a5f75fcfc89b7cdba9c08274e3a53
4
+ data.tar.gz: 8180af54ac20004c003e4ff8db81f360cbad2387
5
5
  SHA512:
6
- metadata.gz: fc6d9de5929616c3c87a780b7d45d3ce8f08ff1f382936868965c6beb992496858377c71e098d8f9936b9751258eea109b0c4b385b9e815162e0ce7ea0b5087c
7
- data.tar.gz: 661a448b214094dee8f0835054817b8121de497c255e02121b72ac58c3aa31dc1b6fbf00696b946810035c36491bdbe617436478edad1e7dbb948d2693a2433a
6
+ metadata.gz: 1f327774005b652a257346a7007ca6b3dfc79ac30ea6b1dd125500629478051ec53fb22023052f609d9003aeb2e544d38bc42b721397cd6c2cb47af696823764
7
+ data.tar.gz: 0c16fbe5446519fee9b9b4111791e407ff20435e8abb29ae9e16c0c3ae9e8f03782353f1140c56bfdb01c8bf53aa1a601c88445a02fd0279a560ae43c48f909d
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2017-08-15
10
+ ### Added
11
+ - Add support for lists (arrays)
12
+
13
+ ### Changed
14
+ - Change `type` in the reducer matchers from classes to dry-types
15
+
16
+ ### Fixed
17
+ - Support empty queries
18
+
19
+ ## [0.1.0] - 2017-08-14
20
+ ### Added
21
+ - Initial implementation of querylicious, with query-parser and query-reducer
22
+
23
+ [Unreleased]: https://github.com/Sonans/querylicious/compare/v0.1.0...HEAD
24
+ [0.1.0]: https://github.com/Sonans/querylicious/compare/v0.0.0...v0.1.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -18,7 +18,8 @@ module Querylicious
18
18
  Types::Strict::Int |
19
19
  Types::Strict::Date |
20
20
  Types::Strict::DateTime |
21
- Types::Strict::Range
21
+ Types::Strict::Range |
22
+ Types::Strict::Array
22
23
  attribute :op, Operators.optional.default(:eql)
23
24
  end
24
25
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry-matcher'
4
+ require 'querylicious/types'
4
5
 
5
6
  module Querylicious
6
7
  # A matcher for query key-value pairs
@@ -9,18 +10,18 @@ module Querylicious
9
10
  # matchers
10
11
  class Evaluator < Dry::Matcher::Evaluator
11
12
  def phrase(&block)
12
- key('phrase', op: :eql, type: ::String, &block)
13
+ key('phrase', op: :eql, type: Types::Strict::String, &block)
13
14
  end
14
15
 
15
16
  def not_phrase(&block)
16
- key('phrase', op: :not_eql, type: ::String, &block)
17
+ key('phrase', op: :not_eql, type: Types::Strict::String, &block)
17
18
  end
18
19
  end
19
20
 
20
21
  CASES = {
21
22
  key: Dry::Matcher::Case.new(
22
- match: lambda do |pair, key, op: :eql, type: Object|
23
- pair.key == key && pair.op == op && pair.value.is_a?(type)
23
+ match: lambda do |pair, key, op: :eql, type: Types::Any|
24
+ pair.key == key && pair.op == op && type.valid?(pair.value)
24
25
  end,
25
26
  resolve: ->(pair) { pair.value }
26
27
  ),
@@ -6,7 +6,7 @@ module Querylicious
6
6
  # Parser for Querylicious search queries
7
7
  class Parser < Parslet::Parser
8
8
  rule(:expression) do
9
- (kv_pair | phrase) >> (space >> expression).repeat
9
+ ((kv_pair | phrase) >> (space >> expression).repeat).maybe
10
10
  end
11
11
 
12
12
  rule(:phrase) do
@@ -22,12 +22,12 @@ module Querylicious
22
22
 
23
23
  rule(:key) { word }
24
24
  rule(:value) do
25
- range | (kv_op.as(:op).maybe >> (datetime | integer | word | string))
25
+ list | range | (kv_op.as(:op).maybe >> (datetime | integer | word | string))
26
26
  end
27
27
 
28
28
  rule(:kv_op) { (str('>=') | str('>') | str('<=') | str('<')).as(:symbol) }
29
29
 
30
- rule(:word) { match('[[:graph:]&&[^":.]]').repeat(1).as(:string) }
30
+ rule(:word) { match('[[:graph:]&&[^":.,]]').repeat(1).as(:string) }
31
31
  rule(:string) do
32
32
  quotemark >> match('[[^"]&&[:print:]]').repeat(0).as(:string) >> quotemark
33
33
  end
@@ -39,6 +39,14 @@ module Querylicious
39
39
  (star | datetime | integer | word).as(:end)
40
40
  ).as(:range)
41
41
  end
42
+
43
+ rule(:list) do
44
+ ((range | datetime | integer | word | string) >>
45
+ (comma >>
46
+ (range | datetime | integer | word | string)).repeat(1)
47
+ ).as(:list)
48
+ end
49
+
42
50
  rule(:datetime) do
43
51
  (date >> str('T') >> time).as(:datetime) | date.as(:date)
44
52
  end
@@ -56,6 +64,7 @@ module Querylicious
56
64
  rule(:quotemark) { match('"') }
57
65
  rule(:star) { str('*').as(:symbol) }
58
66
  rule(:dotdot) { str('..') }
67
+ rule(:comma) { str(',') }
59
68
 
60
69
  rule(:space) { match('[[:space:]]').repeat(1) }
61
70
  rule(:space?) { space.maybe }
@@ -43,7 +43,7 @@ module Querylicious
43
43
  end
44
44
 
45
45
  def parse_query(query)
46
- Array(transformer.apply(parser.parse(query.strip)))
46
+ Array(transformer.apply(parser.parse(query.to_s.strip)))
47
47
  end
48
48
  end
49
49
  end
@@ -8,6 +8,7 @@ require 'querylicious/key_value_pair'
8
8
  module Querylicious
9
9
  # Transformer for turning a parsed query string into a list of KeyValuePair
10
10
  class Transform < Parslet::Transform
11
+ rule('') { nil }
11
12
  rule(string: simple(:it)) { Types::Coercible::String[it] }
12
13
  rule(integer: simple(:it)) { Types::Form::Int[it] }
13
14
  rule(date: simple(:it)) { Types::Form::Date[it] }
@@ -28,6 +29,8 @@ module Querylicious
28
29
  end
29
30
  end
30
31
 
32
+ rule( list: sequence(:it)) { Types::Form::Array[it] }
33
+
31
34
  rule(range: { start: simple(:first), end: simple(:last) }) do
32
35
  if first == :* && last == :*
33
36
  :*
@@ -58,6 +61,13 @@ module Querylicious
58
61
  KeyValuePair.new(key: key, value: value, op: op)
59
62
  end
60
63
 
64
+ rule(pair: { key: simple(:key), value: sequence(:value) }) do
65
+ KeyValuePair.new(key: key, value: value)
66
+ end
67
+ rule(pair: { key: simple(:key), value: sequence(:value), op: simple(:op) }) do
68
+ KeyValuePair.new(key: key, value: value, op: op)
69
+ end
70
+
61
71
  rule(op: simple(:op), string: simple(:it)) do
62
72
  { object: Types::Coercible::String[it], op: op }
63
73
  end
data/querylicious.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  end
19
19
  spec.require_paths = %w[lib]
20
20
 
21
+ spec.required_ruby_version = '>= 2.3'
22
+
21
23
  spec.add_runtime_dependency 'parslet', '~> 1.8'
22
24
  spec.add_runtime_dependency 'dry-matcher', '~> 0.6.0'
23
25
  spec.add_runtime_dependency 'dry-types', '~> 0.11.0'
@@ -25,9 +27,11 @@ Gem::Specification.new do |spec|
25
27
  spec.add_runtime_dependency 'dry-initializer', '~> 1.4'
26
28
 
27
29
  spec.add_development_dependency 'bundler', '~> 1.15'
28
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rake', '~> 12.0'
31
+ spec.add_development_dependency 'reek', '~> 4.7'
29
32
  spec.add_development_dependency 'rspec', '~> 3.0'
30
33
  spec.add_development_dependency 'rspec-parameterized', '~> 0.4.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.49.1'
31
35
  spec.add_development_dependency 'pry', '~> 0.10.4'
32
- spec.add_development_dependency 'simplecov', '~> 0.14.1'
36
+ spec.add_development_dependency 'simplecov', '~> 0.15.0'
33
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: querylicious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo-Herman Haugholt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet
@@ -100,14 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: '12.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: '12.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: reek
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
152
  version: 0.4.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.49.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.49.1
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: pry
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +184,14 @@ dependencies:
156
184
  requirements:
157
185
  - - "~>"
158
186
  - !ruby/object:Gem::Version
159
- version: 0.14.1
187
+ version: 0.15.0
160
188
  type: :development
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
192
  - - "~>"
165
193
  - !ruby/object:Gem::Version
166
- version: 0.14.1
194
+ version: 0.15.0
167
195
  description:
168
196
  email:
169
197
  - jo-herman@sonans.no
@@ -174,6 +202,7 @@ files:
174
202
  - ".reek"
175
203
  - ".rspec"
176
204
  - ".rubocop.yml"
205
+ - CHANGELOG.md
177
206
  - CODE_OF_CONDUCT.md
178
207
  - Gemfile
179
208
  - LICENSE.txt
@@ -202,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
231
  requirements:
203
232
  - - ">="
204
233
  - !ruby/object:Gem::Version
205
- version: '0'
234
+ version: '2.3'
206
235
  required_rubygems_version: !ruby/object:Gem::Requirement
207
236
  requirements:
208
237
  - - ">="