pursuit 0.4.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubygem.yaml +46 -0
- data/Gemfile +14 -13
- data/Gemfile.lock +14 -13
- data/README.md +210 -27
- data/bin/console +10 -0
- data/lib/pursuit/aggregate_modifier_not_found.rb +20 -0
- data/lib/pursuit/aggregate_modifier_required.rb +20 -0
- data/lib/pursuit/aggregate_modifiers_not_available.rb +13 -0
- data/lib/pursuit/attribute_not_found.rb +20 -0
- data/lib/pursuit/constants.rb +1 -1
- data/lib/pursuit/error.rb +7 -0
- data/lib/pursuit/predicate_parser.rb +181 -0
- data/lib/pursuit/predicate_search.rb +86 -0
- data/lib/pursuit/predicate_transform.rb +231 -0
- data/lib/pursuit/query_error.rb +7 -0
- data/lib/pursuit/simple_search.rb +66 -0
- data/lib/pursuit/term_parser.rb +44 -0
- data/lib/pursuit/term_search.rb +74 -0
- data/lib/pursuit/term_transform.rb +35 -0
- data/lib/pursuit.rb +18 -4
- data/pursuit.gemspec +4 -3
- data/spec/internal/app/models/application_record.rb +5 -0
- data/spec/internal/app/models/product.rb +3 -14
- data/spec/internal/app/models/product_category.rb +3 -1
- data/spec/internal/app/models/product_variation.rb +3 -1
- data/spec/internal/app/searches/product_category_search.rb +50 -0
- data/spec/internal/app/searches/product_search.rb +53 -0
- data/spec/internal/app/searches/product_variation_search.rb +53 -0
- data/spec/lib/pursuit/predicate_parser_spec.rb +1604 -0
- data/spec/lib/pursuit/predicate_search_spec.rb +116 -0
- data/spec/lib/pursuit/predicate_transform_spec.rb +624 -0
- data/spec/lib/pursuit/simple_search_spec.rb +73 -0
- data/spec/lib/pursuit/term_parser_spec.rb +271 -0
- data/spec/lib/pursuit/term_search_spec.rb +85 -0
- data/spec/lib/pursuit/term_transform_spec.rb +105 -0
- metadata +50 -25
- data/.travis.yml +0 -26
- data/lib/pursuit/dsl.rb +0 -28
- data/lib/pursuit/railtie.rb +0 -13
- data/lib/pursuit/search.rb +0 -172
- data/lib/pursuit/search_options.rb +0 -86
- data/lib/pursuit/search_term_parser.rb +0 -46
- data/spec/lib/pursuit/dsl_spec.rb +0 -22
- data/spec/lib/pursuit/search_options_spec.rb +0 -146
- data/spec/lib/pursuit/search_spec.rb +0 -516
- data/spec/lib/pursuit/search_term_parser_spec.rb +0 -34
- data/travis/gemfiles/5.2.gemfile +0 -8
- data/travis/gemfiles/6.0.gemfile +0 -8
- data/travis/gemfiles/6.1.gemfile +0 -8
- data/travis/gemfiles/7.0.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e763ac9fa96f98268f46e1824852e5908874fd7b667a8e5e8df5049ad14cd1
|
4
|
+
data.tar.gz: a375cf25c07d547f4bf8321796de8537881a05c740a198269ab6b4dac6c90ad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317ec03777606abbc9c800b728a99305855ae7e4702a64eba53c68ba402e7645de7c21d91ac2d41c8cfd953c3f9a9f1ff9878776c058ab6f39a303d216858c4c
|
7
|
+
data.tar.gz: ca1240b3907b70541a9a26fd54a9c97088deef1d227eb26694085ed99f8c84782cb65b7a22ee9c97d2854b9329ceb30bf6a98ab7900d077fb99047961d0b72b9
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: RubyGem
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
push:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
rubocop:
|
9
|
+
name: RuboCop
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- name: Checkout Source Code
|
13
|
+
uses: actions/checkout@v3
|
14
|
+
- name: Setup Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
- name: Setup RubyGems
|
17
|
+
run: |
|
18
|
+
bundle install
|
19
|
+
- name: RuboCop
|
20
|
+
run: |
|
21
|
+
bundle exec rubocop --parallel --format progress --format html --out rubocop-report.html
|
22
|
+
- name: Upload Report
|
23
|
+
uses: actions/upload-artifact@v3
|
24
|
+
with:
|
25
|
+
name: RuboCop Report
|
26
|
+
path: rubocop-report.html
|
27
|
+
|
28
|
+
rspec:
|
29
|
+
name: RSpec
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
steps:
|
32
|
+
- name: Checkout Source Code
|
33
|
+
uses: actions/checkout@v3
|
34
|
+
- name: Setup Ruby
|
35
|
+
uses: ruby/setup-ruby@v1
|
36
|
+
- name: Setup RubyGems
|
37
|
+
run: |
|
38
|
+
bundle install
|
39
|
+
- name: RSpec
|
40
|
+
run: |
|
41
|
+
bundle exec rspec --format progress --format html --out rspec-report.html
|
42
|
+
- name: Upload Report
|
43
|
+
uses: actions/upload-artifact@v3
|
44
|
+
with:
|
45
|
+
name: RSpec Report
|
46
|
+
path: rspec-report.html
|
data/Gemfile
CHANGED
@@ -4,16 +4,17 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
|
8
|
-
gem 'combustion', '~> 1.3'
|
9
|
-
gem 'guard', '~> 2.18'
|
10
|
-
gem 'guard-rspec', '~> 4.7'
|
11
|
-
gem 'pry', '~> 0.14'
|
12
|
-
gem 'rake', '~> 13.0'
|
13
|
-
gem 'rspec', '~> 3.12'
|
14
|
-
gem 'rspec-rails', '~> 6.0'
|
15
|
-
gem 'rubocop', '~> 1.57'
|
16
|
-
gem 'rubocop-rake', '~> 0.6'
|
17
|
-
gem 'rubocop-rspec', '~> 2.25'
|
18
|
-
gem 'sqlite3', '~> 1.6'
|
19
|
-
gem 'yard', '~> 0.9'
|
7
|
+
group :development do
|
8
|
+
gem 'combustion', '~> 1.3'
|
9
|
+
gem 'guard', '~> 2.18'
|
10
|
+
gem 'guard-rspec', '~> 4.7'
|
11
|
+
gem 'pry', '~> 0.14'
|
12
|
+
gem 'rake', '~> 13.0'
|
13
|
+
gem 'rspec', '~> 3.12'
|
14
|
+
gem 'rspec-rails', '~> 6.0'
|
15
|
+
gem 'rubocop', '~> 1.57'
|
16
|
+
gem 'rubocop-rake', '~> 0.6'
|
17
|
+
gem 'rubocop-rspec', '~> 2.25'
|
18
|
+
gem 'sqlite3', '~> 1.6'
|
19
|
+
gem 'yard', '~> 0.9'
|
20
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pursuit (0.
|
5
|
-
activerecord (>= 5.2.0,
|
6
|
-
activesupport (>= 5.2.0,
|
4
|
+
pursuit (1.0.1)
|
5
|
+
activerecord (>= 5.2.0, <= 8.0.0)
|
6
|
+
activesupport (>= 5.2.0, <= 8.0.0)
|
7
|
+
parslet (~> 2.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
@@ -90,7 +91,7 @@ GEM
|
|
90
91
|
minitest (5.20.0)
|
91
92
|
mutex_m (0.1.2)
|
92
93
|
nenv (0.3.0)
|
93
|
-
nokogiri (1.15.4-
|
94
|
+
nokogiri (1.15.4-arm-linux)
|
94
95
|
racc (~> 1.4)
|
95
96
|
nokogiri (1.15.4-arm64-darwin)
|
96
97
|
racc (~> 1.4)
|
@@ -105,12 +106,13 @@ GEM
|
|
105
106
|
parser (3.2.2.4)
|
106
107
|
ast (~> 2.4.1)
|
107
108
|
racc
|
109
|
+
parslet (2.0.0)
|
108
110
|
pry (0.14.2)
|
109
111
|
coderay (~> 1.1)
|
110
112
|
method_source (~> 1.0)
|
111
113
|
psych (5.1.1.1)
|
112
114
|
stringio
|
113
|
-
racc (1.7.
|
115
|
+
racc (1.7.2)
|
114
116
|
rack (3.0.8)
|
115
117
|
rack-session (2.0.0)
|
116
118
|
rack (>= 3.0.0)
|
@@ -135,7 +137,7 @@ GEM
|
|
135
137
|
thor (~> 1.0, >= 1.2.2)
|
136
138
|
zeitwerk (~> 2.6)
|
137
139
|
rainbow (3.1.1)
|
138
|
-
rake (13.0
|
140
|
+
rake (13.1.0)
|
139
141
|
rb-fsevent (0.11.2)
|
140
142
|
rb-inotify (0.10.1)
|
141
143
|
ffi (~> 1.0)
|
@@ -192,10 +194,10 @@ GEM
|
|
192
194
|
ruby-progressbar (1.13.0)
|
193
195
|
ruby2_keywords (0.0.5)
|
194
196
|
shellany (0.0.1)
|
195
|
-
sqlite3 (1.6.
|
196
|
-
sqlite3 (1.6.
|
197
|
-
sqlite3 (1.6.
|
198
|
-
sqlite3 (1.6.
|
197
|
+
sqlite3 (1.6.8-arm-linux)
|
198
|
+
sqlite3 (1.6.8-arm64-darwin)
|
199
|
+
sqlite3 (1.6.8-x86_64-darwin)
|
200
|
+
sqlite3 (1.6.8-x86_64-linux)
|
199
201
|
stringio (3.0.8)
|
200
202
|
thor (1.3.0)
|
201
203
|
timeout (0.4.0)
|
@@ -207,13 +209,12 @@ GEM
|
|
207
209
|
zeitwerk (2.6.12)
|
208
210
|
|
209
211
|
PLATFORMS
|
210
|
-
aarch64-linux
|
211
212
|
arm64-darwin-22
|
212
|
-
|
213
|
+
arm64-linux
|
214
|
+
x86_64-darwin-22
|
213
215
|
x86_64-linux
|
214
216
|
|
215
217
|
DEPENDENCIES
|
216
|
-
bundler (~> 2.4)
|
217
218
|
combustion (~> 1.3)
|
218
219
|
guard (~> 2.18)
|
219
220
|
guard-rspec (~> 4.7)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Pursuit
|
2
2
|
|
3
|
-
|
3
|
+
Search your ActiveRecord objects with ease!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,41 +16,224 @@ gem 'pursuit'
|
|
16
16
|
|
17
17
|
### Usage
|
18
18
|
|
19
|
-
|
19
|
+
Pursuit comes with three different strategies for interpreting queries:
|
20
|
+
|
21
|
+
- Simple
|
22
|
+
- Term
|
23
|
+
- Predicate
|
24
|
+
|
25
|
+
### Simple Search
|
26
|
+
|
27
|
+
Simple takes the entire query and generates a SQL `LIKE` (or `ILIKE` for *PostgreSQL*) statement for each attribute
|
28
|
+
added to the search instance. Here's an example of how you might use simple to search a hypothetical `Product` record:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
search = Pursuit::SimpleSearch.new(default_table: Product.arel_table)
|
32
|
+
search.search_attribute(:title)
|
33
|
+
search.search_attribute(:subtitle)
|
34
|
+
search.apply('Green Shirt', Product.all)
|
35
|
+
```
|
36
|
+
|
37
|
+
Which results in the following SQL query:
|
38
|
+
|
39
|
+
```sql
|
40
|
+
SELECT
|
41
|
+
"products".*
|
42
|
+
FROM
|
43
|
+
"products"
|
44
|
+
WHERE
|
45
|
+
"products"."title" LIKE '%Green Shirt%'
|
46
|
+
OR "products"."subtitle" LIKE '%Green Shirt%'
|
47
|
+
```
|
48
|
+
|
49
|
+
The initializer method also accepts a block, which is evaluated within the instance's context. This can make it cleaner
|
50
|
+
when declaring the searchable attributes:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
search = Pursuit::SimpleSearch.new(default_table: Product.arel_table) do
|
54
|
+
search_attribute :title
|
55
|
+
search_attribute :subtitle
|
56
|
+
end
|
57
|
+
|
58
|
+
search.apply('Green Shirt', Product.all)
|
59
|
+
```
|
60
|
+
|
61
|
+
You can also pass custom `Arel::Attribute::Attribute` objects, which are especially useful when using joins:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
search = Pursuit::SimpleSearch.new(default_table: Product.arel_table) do
|
65
|
+
search_attribute :title
|
66
|
+
search_attribute ProductVariation.arel_table[:title]
|
67
|
+
end
|
68
|
+
|
69
|
+
search.apply('Green Shirt', Product.left_outer_joins(:variations).group(:id))
|
70
|
+
```
|
71
|
+
|
72
|
+
Which results in the following SQL query:
|
73
|
+
|
74
|
+
```sql
|
75
|
+
SELECT
|
76
|
+
"products".*
|
77
|
+
FROM
|
78
|
+
"products"
|
79
|
+
LEFT OUTER JOIN "product_variations" ON "product_variations"."product_id" = "products"."id"
|
80
|
+
WHERE
|
81
|
+
"products"."title" LIKE '%Green Shirt%'
|
82
|
+
OR "product_variations"."title" LIKE '%Green Shirt%'
|
83
|
+
GROUP BY
|
84
|
+
"products"."id"
|
85
|
+
```
|
86
|
+
|
87
|
+
### Term Search
|
88
|
+
|
89
|
+
Term searches break a query into individual terms on spaces, while providing double and single quoted strings as a
|
90
|
+
means to include spaces. Here's an example of using term searches on the same `Product` record from earlier:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
search = Pursuit::TermSearch.new(default_table: Product.arel_table) do
|
94
|
+
search_attribute :title
|
95
|
+
search_attribute :subtitle
|
96
|
+
end
|
97
|
+
|
98
|
+
search.apply('Green "Luxury Shirt"', Product.all)
|
99
|
+
```
|
100
|
+
|
101
|
+
Which results in a SQL query similar to the following:
|
102
|
+
|
103
|
+
```sql
|
104
|
+
SELECT
|
105
|
+
"products".*
|
106
|
+
FROM
|
107
|
+
"products"
|
108
|
+
WHERE
|
109
|
+
(
|
110
|
+
"products"."title" LIKE '%Green%'
|
111
|
+
OR "products"."subtitle" LIKE '%Green%'
|
112
|
+
) AND (
|
113
|
+
"products"."title" LIKE '%Luxury Shirt%'
|
114
|
+
OR "products"."subtitle" LIKE '%Luxury Shirt%'
|
115
|
+
)
|
116
|
+
```
|
117
|
+
|
118
|
+
### Predicate Search
|
119
|
+
|
120
|
+
Predicate searches use a parser (implemented with the `parslet` gem) to provide a minimal query language.
|
121
|
+
This syntax is similar to the `WHERE` and `HAVING` clauses in SQL, but uses only symbols for operators and joins.
|
122
|
+
|
123
|
+
Attributes can only be used in predicate searches when they have been added to the list of permitted attributes.
|
124
|
+
You can also rename attributes, and add attributes for joined records.
|
125
|
+
|
126
|
+
Here's a more complex example of using predicate-based searches with joins on the `Product` record from earlier:
|
20
127
|
|
21
128
|
```ruby
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# as the second argument.
|
34
|
-
# => "category*=shirts"
|
35
|
-
o.attribute :category, :category_id
|
36
|
-
|
37
|
-
# It's also possible to query entirely custom Arel nodes by passing a block which returns the Arel node to query.
|
38
|
-
# You could use this to query a person's full name by concatenating their first and last name columns, for example.
|
39
|
-
o.attribute :title_length, unkeyed: false do
|
40
|
-
Arel::Nodes::NamedFunction.new('LENGTH', [
|
41
|
-
arel_table[:title]
|
42
|
-
])
|
43
|
-
end
|
44
|
-
end
|
129
|
+
search = Pursuit::PredicateSearch.new(default_table: Product.arel_table) do
|
130
|
+
# Product Attributes
|
131
|
+
permit_attribute :title
|
132
|
+
|
133
|
+
# Product Category Attributes
|
134
|
+
permit_attribute :category_name, ProductCategory.arel_table[:name]
|
135
|
+
|
136
|
+
# Product Variation Attributes
|
137
|
+
permit_attribute :variation_title, ProductVariation.arel_table[:title]
|
138
|
+
permit_attribute :variation_currency, ProductVariation.arel_table[:currency]
|
139
|
+
permit_attribute :variation_amount, ProductVariation.arel_table[:amount]
|
45
140
|
end
|
141
|
+
|
142
|
+
search.apply(
|
143
|
+
'title = "Luxury Shirt" & (variation_amount = 0 | variation_amount > 1000)',
|
144
|
+
Product.left_outer_join(:category, :variations).group(:id)
|
145
|
+
)
|
46
146
|
```
|
47
147
|
|
48
|
-
This
|
148
|
+
This translates to "a product whose title is 'Luxury Shirt' and has at least one variation with either an amount of 0,
|
149
|
+
or an amount greater than 1000", which could be expressed in SQL as:
|
150
|
+
|
151
|
+
```sql
|
152
|
+
SELECT
|
153
|
+
"products".*
|
154
|
+
FROM
|
155
|
+
"products"
|
156
|
+
LEFT OUTER JOIN "product_categories" ON "product_categories"."id" = "products"."category_id"
|
157
|
+
LEFT OUTER JOIN "product_variations" ON "product_variations"."product_id" = "products"."id"
|
158
|
+
WHERE
|
159
|
+
"products"."title" = 'Luxury Shirt'
|
160
|
+
AND (
|
161
|
+
"product_variations"."amount" = 0
|
162
|
+
OR "product_variations"."amount" > 1000
|
163
|
+
)
|
164
|
+
GROUP BY
|
165
|
+
"products"."id"
|
166
|
+
```
|
167
|
+
|
168
|
+
You can use any of the following operators in comparisons:
|
169
|
+
|
170
|
+
- `=` checks if the attribute is equal to the value.
|
171
|
+
- `!=` checks if the attributes is not equal to the value.
|
172
|
+
- `>` checks if the attribute is greater than the value.
|
173
|
+
- `<` checks if the attribute is less than the value.
|
174
|
+
- `>=` checks if the attribute is greater than or equal to the value.
|
175
|
+
- `<=` checks if the attribute is less than or equal to the value.
|
176
|
+
- `~` checks if the attribute matches the value (using `LIKE` or `ILIKE`).
|
177
|
+
- `!~` checks if the attribute does not match the value (using `LIKE` or `ILIKE`).
|
178
|
+
|
179
|
+
Predicate searches also support "aggregate modifiers" which enable the use of aggregate functions, however this feature
|
180
|
+
must be explicitly enabled and requires you to use a `GROUP BY` clause:
|
49
181
|
|
50
182
|
```ruby
|
51
|
-
|
183
|
+
search = Pursuit::PredicateSearch.new(default_table: Product.arel_table, permit_aggregate_modifiers: true) do
|
184
|
+
# Product Attributes
|
185
|
+
permit_attribute :title
|
186
|
+
|
187
|
+
# Product Category Attributes
|
188
|
+
permit_attribute :category, ProductCategory.arel_table[:id]
|
189
|
+
permit_attribute :category_name, ProductCategory.arel_table[:name]
|
190
|
+
|
191
|
+
# Product Variation Attributes
|
192
|
+
permit_attribute :variation, ProductVariation.arel_table[:id]
|
193
|
+
permit_attribute :variation_title, ProductVariation.arel_table[:title]
|
194
|
+
permit_attribute :variation_currency, ProductVariation.arel_table[:currency]
|
195
|
+
permit_attribute :variation_amount, ProductVariation.arel_table[:amount]
|
196
|
+
end
|
197
|
+
|
198
|
+
search.apply(
|
199
|
+
'title = "Luxury Shirt" & #variation > 5',
|
200
|
+
Product.left_outer_join(:category, :variations).group(:id)
|
201
|
+
)
|
52
202
|
```
|
53
203
|
|
204
|
+
And the resulting SQL from this query:
|
205
|
+
|
206
|
+
```sql
|
207
|
+
SELECT
|
208
|
+
"products".*
|
209
|
+
FROM
|
210
|
+
"products"
|
211
|
+
LEFT OUTER JOIN "product_categories" ON "product_categories"."id" = "products"."category_id"
|
212
|
+
LEFT OUTER JOIN "product_variations" ON "product_variations"."product_id" = "products"."id"
|
213
|
+
WHERE
|
214
|
+
"products"."title" = 'Luxury Shirt'
|
215
|
+
GROUP BY
|
216
|
+
"products"."id"
|
217
|
+
HAVING
|
218
|
+
COUNT("product_variations"."id") > 5
|
219
|
+
```
|
220
|
+
|
221
|
+
There's no distinction between the `WHERE` and `HAVING` clause in the predicate syntax, as it's intended to be easy to
|
222
|
+
use, but this does come with a caveat.
|
223
|
+
|
224
|
+
The query must have all aggregate-modified comparisons before or after non-aggregate-modified comparisons, you can't
|
225
|
+
mix both.
|
226
|
+
|
227
|
+
For example, this query would result in a parsing error: `title ~ Shirt & #variation > 5 & category_name = Shirts`
|
228
|
+
|
229
|
+
You can preceed any attribute with one of these aggregate modifier symbols:
|
230
|
+
|
231
|
+
- `#` uses the `COUNT` aggregate function
|
232
|
+
- `+` uses the `MAX` aggregate function
|
233
|
+
- `-` uses the `MIN` aggregate function
|
234
|
+
- `*` uses the `SUM` aggregate function
|
235
|
+
- `~` uses the `AVG` aggregate function
|
236
|
+
|
54
237
|
## Development
|
55
238
|
|
56
239
|
After checking out the repo, run `bundle exec rake spec` to run the tests.
|
data/bin/console
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
3
5
|
require 'bundler/setup'
|
4
6
|
require 'pursuit'
|
5
7
|
require 'pry'
|
6
8
|
|
9
|
+
if ENV['AR'] == 'true'
|
10
|
+
require 'combustion'
|
11
|
+
Combustion.initialize!(:active_record)
|
12
|
+
|
13
|
+
require 'bundler'
|
14
|
+
Bundler.require(:default, :development)
|
15
|
+
end
|
16
|
+
|
7
17
|
Pry.start
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pursuit
|
4
|
+
# Raised when an aggregate modifier cannot be found.
|
5
|
+
#
|
6
|
+
class AggregateModifierNotFound < QueryError
|
7
|
+
# @return [String] The aggregate modifier which does not map to an aggregate function.
|
8
|
+
#
|
9
|
+
attr_reader :aggregate_modifier
|
10
|
+
|
11
|
+
# Creates a new error instance.
|
12
|
+
#
|
13
|
+
# @param aggregate_modifier [Symbol] The aggregate modifier which does not map to an aggregate function.
|
14
|
+
#
|
15
|
+
def initialize(aggregate_modifier)
|
16
|
+
@aggregate_modifier = aggregate_modifier
|
17
|
+
super("#{aggregate_modifier} is not a valid aggregate modifier")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pursuit
|
4
|
+
# Raised when an attribute that must be used with an aggregate modifier is used without one.
|
5
|
+
#
|
6
|
+
class AggregateModifierRequired < QueryError
|
7
|
+
# @return [Symbol] The name of the attribute which must be used with an aggregate modifier.
|
8
|
+
#
|
9
|
+
attr_reader :attribute
|
10
|
+
|
11
|
+
# Creates a new error instance.
|
12
|
+
#
|
13
|
+
# @param attribute [Symbol] The name of the attribute which must be used with an aggregate modifier.
|
14
|
+
#
|
15
|
+
def initialize(attribute)
|
16
|
+
@attribute = attribute
|
17
|
+
super("'#{attribute}' must be used with an aggregate modifier")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pursuit
|
4
|
+
# Raised when an aggregate modifier is used in a query, but aggregate modifiers are not available.
|
5
|
+
#
|
6
|
+
class AggregateModifiersNotAvailable < QueryError
|
7
|
+
# Creates a new error instance.
|
8
|
+
#
|
9
|
+
def initialize
|
10
|
+
super('Aggregate modifiers cannot be used in this query')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pursuit
|
4
|
+
# Raised when an attribute cannot be found.
|
5
|
+
#
|
6
|
+
class AttributeNotFound < QueryError
|
7
|
+
# @return [Symbol] The name of the attribute which could not be found.
|
8
|
+
#
|
9
|
+
attr_reader :attribute
|
10
|
+
|
11
|
+
# Creates a new error instance.
|
12
|
+
#
|
13
|
+
# @param attribute [Symbol] The name of the attribute which could not be found.
|
14
|
+
#
|
15
|
+
def initialize(attribute)
|
16
|
+
@attribute = attribute
|
17
|
+
super("'#{attribute}' is not a valid attribute")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/pursuit/constants.rb
CHANGED