trailblazer-finder 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +160 -11
- data/CHANGES.md +5 -0
- data/README.md +93 -22
- data/lib/trailblazer/finder.rb +3 -0
- data/lib/trailblazer/finder/adapters/active_record.rb +4 -0
- data/lib/trailblazer/finder/adapters/active_record/predicates.rb +42 -0
- data/lib/trailblazer/finder/adapters/friendly_id.rb +22 -24
- data/lib/trailblazer/finder/adapters/sequel.rb +5 -0
- data/lib/trailblazer/finder/adapters/sequel/predicates.rb +43 -0
- data/lib/trailblazer/finder/base.rb +3 -3
- data/lib/trailblazer/finder/features.rb +1 -0
- data/lib/trailblazer/finder/features/predicate.rb +37 -0
- data/lib/trailblazer/finder/filter.rb +2 -2
- data/lib/trailblazer/finder/predicates.rb +39 -0
- data/lib/trailblazer/finder/utils/deep_locate.rb +45 -0
- data/lib/trailblazer/finder/utils/extra.rb +1 -1
- data/lib/trailblazer/finder/utils/splitter.rb +42 -0
- data/lib/trailblazer/finder/version.rb +1 -1
- data/spec/spec_helper_sequel.rb +1 -0
- data/spec/trailblazer/finder/adapters/active_record/base_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/active_record/predicates_spec.rb +98 -0
- data/spec/trailblazer/finder/adapters/active_record/sorting_spec.rb +4 -0
- data/spec/trailblazer/finder/adapters/data_mapper/base_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/sequel/base_spec.rb +1 -1
- data/spec/trailblazer/finder/adapters/sequel/predicates_spec.rb +89 -0
- data/spec/trailblazer/finder/adapters/sequel/sorting_spec.rb +4 -0
- data/spec/trailblazer/finder/features/paging_spec.rb +1 -1
- data/spec/trailblazer/finder/features/predicates_spec.rb +99 -0
- data/spec/trailblazer/finder/features/sorting_spec.rb +3 -4
- data/spec/trailblazer/operation/predicates_spec.rb +127 -0
- data/spec/trailblazer/test_spec.rb +41 -0
- data/trailblazer-finder.gemspec +0 -2
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4608d8c90233e27fe50241948f60646d3b68babc3555357291586f83bad3f6e
|
4
|
+
data.tar.gz: 04fd61382d1ba953bbb36f115a7dad6491df8c8b86622593d859b000a16cdf69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7723c58c1ecccad895806fde42004a1b74d478ed87020f0ea022f1e146854909c246cb7bd6e64e0bbc3c7f585a29c4bcb3d351b309bcaaa5f4fa52d581c4f219
|
7
|
+
data.tar.gz: 129524c2f2ab3ac5249cdacd941405239a0f1389534b7418005e1b31bb8cba712e49df7454257047fa8a0361d1e4e0098dc2e1dafcd2925ffb77363e0a365c1e
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-03-
|
3
|
+
# on 2018-03-14 21:09:38 +0100 using RuboCop version 0.53.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -8,11 +8,9 @@
|
|
8
8
|
|
9
9
|
# Offense count: 1
|
10
10
|
# Cop supports --auto-correct.
|
11
|
-
|
12
|
-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
13
|
-
Bundler/OrderedGems:
|
11
|
+
Layout/CommentIndentation:
|
14
12
|
Exclude:
|
15
|
-
- '
|
13
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
16
14
|
|
17
15
|
# Offense count: 1
|
18
16
|
# Cop supports --auto-correct.
|
@@ -20,14 +18,123 @@ Layout/EmptyLines:
|
|
20
18
|
Exclude:
|
21
19
|
- 'spec/trailblazer/operation/finder_spec.rb'
|
22
20
|
|
23
|
-
# Offense count:
|
21
|
+
# Offense count: 1
|
22
|
+
# Cop supports --auto-correct.
|
23
|
+
# Configuration parameters: EnforcedStyle.
|
24
|
+
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
|
25
|
+
Layout/EmptyLinesAroundModuleBody:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
# Cop supports --auto-correct.
|
31
|
+
# Configuration parameters: EnforcedStyle.
|
32
|
+
# SupportedStyles: normal, rails
|
33
|
+
Layout/IndentationConsistency:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
36
|
+
|
37
|
+
# Offense count: 1
|
38
|
+
# Cop supports --auto-correct.
|
39
|
+
# Configuration parameters: Width, IgnoredPatterns.
|
40
|
+
Layout/IndentationWidth:
|
41
|
+
Exclude:
|
42
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
43
|
+
|
44
|
+
# Offense count: 1
|
45
|
+
# Cop supports --auto-correct.
|
46
|
+
Layout/SpaceAroundKeyword:
|
47
|
+
Exclude:
|
48
|
+
- 'spec/trailblazer/finder/features/predicates_spec.rb'
|
49
|
+
|
50
|
+
# Offense count: 4
|
51
|
+
# Cop supports --auto-correct.
|
52
|
+
# Configuration parameters: AllowForAlignment.
|
53
|
+
Layout/SpaceAroundOperators:
|
54
|
+
Exclude:
|
55
|
+
- 'spec/trailblazer/finder/features/predicates_spec.rb'
|
56
|
+
|
57
|
+
# Offense count: 4
|
58
|
+
# Cop supports --auto-correct.
|
59
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
|
60
|
+
# SupportedStyles: space, no_space
|
61
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
62
|
+
Layout/SpaceBeforeBlockBraces:
|
63
|
+
Exclude:
|
64
|
+
- 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
|
65
|
+
|
66
|
+
# Offense count: 8
|
67
|
+
# Cop supports --auto-correct.
|
68
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
69
|
+
# SupportedStyles: space, no_space
|
70
|
+
# SupportedStylesForEmptyBraces: space, no_space
|
71
|
+
Layout/SpaceInsideBlockBraces:
|
72
|
+
Exclude:
|
73
|
+
- 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
|
74
|
+
|
75
|
+
# Offense count: 4
|
76
|
+
# Cop supports --auto-correct.
|
77
|
+
Layout/SpaceInsideParens:
|
78
|
+
Exclude:
|
79
|
+
- 'lib/trailblazer/finder/utils/splitter.rb'
|
80
|
+
|
81
|
+
# Offense count: 5
|
82
|
+
# Cop supports --auto-correct.
|
83
|
+
Layout/TrailingWhitespace:
|
84
|
+
Exclude:
|
85
|
+
- 'lib/trailblazer/finder/filter.rb'
|
86
|
+
- 'spec/trailblazer/finder/adapters/active_record/base_spec.rb'
|
87
|
+
- 'spec/trailblazer/finder/adapters/data_mapper/base_spec.rb'
|
88
|
+
- 'spec/trailblazer/finder/adapters/sequel/base_spec.rb'
|
89
|
+
|
90
|
+
# Offense count: 1
|
91
|
+
Lint/DuplicateMethods:
|
92
|
+
Exclude:
|
93
|
+
- 'lib/trailblazer/finder/utils/splitter.rb'
|
94
|
+
|
95
|
+
# Offense count: 2
|
96
|
+
# Cop supports --auto-correct.
|
97
|
+
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
98
|
+
Lint/UnusedMethodArgument:
|
99
|
+
Exclude:
|
100
|
+
- 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
|
101
|
+
|
102
|
+
# Offense count: 2
|
103
|
+
Metrics/AbcSize:
|
104
|
+
Max: 18
|
105
|
+
|
106
|
+
# Offense count: 8
|
107
|
+
# Configuration parameters: CountComments.
|
108
|
+
Metrics/MethodLength:
|
109
|
+
Max: 51
|
110
|
+
|
111
|
+
# Offense count: 5
|
24
112
|
RSpec/DescribeClass:
|
25
113
|
Exclude:
|
114
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
26
115
|
- 'spec/trailblazer/operation/finder_spec.rb'
|
27
116
|
- 'spec/trailblazer/operation/paging_spec.rb'
|
117
|
+
- 'spec/trailblazer/operation/predicates_spec.rb'
|
28
118
|
- 'spec/trailblazer/operation/sorting_spec.rb'
|
29
119
|
|
30
|
-
# Offense count:
|
120
|
+
# Offense count: 40
|
121
|
+
# Configuration parameters: CustomTransform, IgnoredWords.
|
122
|
+
RSpec/ExampleWording:
|
123
|
+
Exclude:
|
124
|
+
- 'spec/trailblazer/finder/adapters/active_record/predicates_spec.rb'
|
125
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
126
|
+
- 'spec/trailblazer/finder/features/predicates_spec.rb'
|
127
|
+
- 'spec/trailblazer/operation/predicates_spec.rb'
|
128
|
+
|
129
|
+
# Offense count: 2
|
130
|
+
# Cop supports --auto-correct.
|
131
|
+
# Configuration parameters: EnforcedStyle.
|
132
|
+
# SupportedStyles: prefer_alias, prefer_alias_method
|
133
|
+
Style/Alias:
|
134
|
+
Exclude:
|
135
|
+
- 'lib/trailblazer/finder/utils/splitter.rb'
|
136
|
+
|
137
|
+
# Offense count: 18
|
31
138
|
# Cop supports --auto-correct.
|
32
139
|
# Configuration parameters: AutoCorrect, EnforcedStyle.
|
33
140
|
# SupportedStyles: nested, compact
|
@@ -35,18 +142,60 @@ Style/ClassAndModuleChildren:
|
|
35
142
|
Exclude:
|
36
143
|
- 'spec/trailblazer/operation/finder_spec.rb'
|
37
144
|
- 'spec/trailblazer/operation/paging_spec.rb'
|
145
|
+
- 'spec/trailblazer/operation/predicates_spec.rb'
|
38
146
|
- 'spec/trailblazer/operation/sorting_spec.rb'
|
39
147
|
|
40
|
-
# Offense count:
|
148
|
+
# Offense count: 1
|
149
|
+
# Cop supports --auto-correct.
|
150
|
+
Style/IfUnlessModifier:
|
151
|
+
Exclude:
|
152
|
+
- 'lib/trailblazer/finder/utils/deep_locate.rb'
|
153
|
+
|
154
|
+
# Offense count: 2
|
155
|
+
# Cop supports --auto-correct.
|
156
|
+
# Configuration parameters: IncludeSemanticChanges.
|
157
|
+
Style/NonNilCheck:
|
158
|
+
Exclude:
|
159
|
+
- 'lib/trailblazer/finder/predicates.rb'
|
160
|
+
|
161
|
+
# Offense count: 2
|
162
|
+
# Cop supports --auto-correct.
|
163
|
+
Style/ParallelAssignment:
|
164
|
+
Exclude:
|
165
|
+
- 'lib/trailblazer/finder/utils/splitter.rb'
|
166
|
+
|
167
|
+
# Offense count: 2
|
168
|
+
# Cop supports --auto-correct.
|
169
|
+
Style/PerlBackrefs:
|
170
|
+
Exclude:
|
171
|
+
- 'lib/trailblazer/finder/utils/splitter.rb'
|
172
|
+
|
173
|
+
# Offense count: 160
|
41
174
|
# Cop supports --auto-correct.
|
42
175
|
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
43
176
|
# SupportedStyles: single_quotes, double_quotes
|
44
177
|
Style/StringLiterals:
|
45
178
|
Exclude:
|
46
|
-
- '
|
179
|
+
- 'lib/trailblazer/finder/adapters/sequel/predicates.rb'
|
180
|
+
- 'lib/trailblazer/finder/features/predicate.rb'
|
181
|
+
- 'spec/trailblazer/finder/adapters/active_record/predicates_spec.rb'
|
182
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
183
|
+
- 'spec/trailblazer/finder/features/predicates_spec.rb'
|
184
|
+
- 'spec/trailblazer/operation/predicates_spec.rb'
|
185
|
+
|
186
|
+
# Offense count: 16
|
187
|
+
# Cop supports --auto-correct.
|
188
|
+
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
|
189
|
+
# SupportedStyles: percent, brackets
|
190
|
+
Style/WordArray:
|
191
|
+
Exclude:
|
192
|
+
- 'spec/trailblazer/finder/adapters/active_record/predicates_spec.rb'
|
193
|
+
- 'spec/trailblazer/finder/adapters/sequel/predicates_spec.rb'
|
194
|
+
- 'spec/trailblazer/finder/features/predicates_spec.rb'
|
195
|
+
- 'spec/trailblazer/operation/predicates_spec.rb'
|
47
196
|
|
48
|
-
# Offense count:
|
197
|
+
# Offense count: 151
|
49
198
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
50
199
|
# URISchemes: http, https
|
51
200
|
Metrics/LineLength:
|
52
|
-
Max:
|
201
|
+
Max: 172
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 0.1.2
|
2
|
+
|
3
|
+
* Predicate feature introduced, doesn't work for old datamapper adapter yet. Default predicates covered for now: eq, not_eq, blank, not_blank, lt, lte, gt, gte
|
4
|
+
* Removed Hashie as dependency and introduced simple version of deep_locate
|
5
|
+
|
1
6
|
# 0.1.1
|
2
7
|
|
3
8
|
* load options[:model] with result set otherwise loading contracts fails, have to find a nicer solution for this at some point
|
data/README.md
CHANGED
@@ -18,25 +18,27 @@ Description should come here
|
|
18
18
|
* [Example without Trailblazer](#example-without-trailblazer)
|
19
19
|
* [Example Project](#example-project)
|
20
20
|
* [Features](#features)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
* [Predicate](#predicate)
|
22
|
+
* [Predicate Example](#predicate-example)
|
23
|
+
* [Paging](#paging)
|
24
|
+
* [Paging Example](#paging-example)
|
25
|
+
* [Sorting](#sorting)
|
26
|
+
* [Sorting Example](#sorting-example)
|
25
27
|
* [Adapters](#adapters)
|
26
|
-
|
27
|
-
|
28
|
+
* [Adapters Example](#adapters-example)
|
29
|
+
* [ActiveRecord](#active_record)
|
28
30
|
* [Active Record Example](#active-record-example)
|
29
|
-
|
31
|
+
* [DataMapper](#data_mapper)
|
30
32
|
* [Data Mapper Example](#data-mapper-example)
|
31
|
-
|
33
|
+
* [Sequel](#sequel)
|
32
34
|
* [Sequel Example](#sequel-example)
|
33
|
-
|
35
|
+
* [Kaminari](#kaminari)
|
34
36
|
* [Kaminari Example](#kaminari-example)
|
35
|
-
|
37
|
+
* [WillPaginate](#will_paginate)
|
36
38
|
* [Will Paginate Example](#will-paginate-example)
|
37
|
-
|
39
|
+
* [FriendlyId](#friendly_id)
|
38
40
|
* [Friendly Id Example](#friendly-id-example)
|
39
|
-
* [Tips & Tricks](#tips--tricks)
|
41
|
+
* [Tips & Tricks](#tips--tricks)
|
40
42
|
* [ORM's are not required](#results-shortcut)
|
41
43
|
* [Passing Entity Type as Argument](#passing-entity_type-as-argument)
|
42
44
|
* [Contributing](#contributing)
|
@@ -59,7 +61,6 @@ Or install it yourself as:
|
|
59
61
|
$ gem install trailblazer-finder
|
60
62
|
|
61
63
|
###
|
62
|
-
* [Hashie](https://github.com/intridea/hashie) - used to search deep within hashes/arrays
|
63
64
|
* [Trailblazer](https://github.com/trailblazer/trailblazer) - [actually optional, but requires 2.1+](https://github.com/trailblazer/trailblazer-finder#usable-without-trailblazer)
|
64
65
|
|
65
66
|
## Usage
|
@@ -201,7 +202,7 @@ When using this, result[:finder] will be extended with (not available for :singl
|
|
201
202
|
|
202
203
|
# params for url generations
|
203
204
|
.params # => filter values
|
204
|
-
.params
|
205
|
+
.params published: false # => overwrites the 'published' filter
|
205
206
|
```
|
206
207
|
|
207
208
|
|
@@ -227,20 +228,92 @@ When using this, result will be extended with (not available for :single row)
|
|
227
228
|
|
228
229
|
# params for url generations
|
229
230
|
.params # => filter values
|
230
|
-
.params
|
231
|
+
.params published: false # => overwrites the 'published' filter
|
231
232
|
```
|
232
233
|
|
233
234
|
### Example Project
|
234
235
|
Coming soon!
|
235
236
|
|
236
237
|
## Features
|
237
|
-
Aside of the default filtering
|
238
|
+
Aside of the default filtering behavior, it offers the following optional features as well.
|
238
239
|
|
239
240
|
NOTE: FEATURES NEED TO BE SPECIFIED ON TOP OF YOUR CLASS
|
240
241
|
|
241
|
-
###
|
242
|
+
### Predicate
|
243
|
+
Simple predicate feature, that enables you to have default predicate filters available for the specified fields.
|
244
|
+
|
245
|
+
At the moment we support:
|
246
|
+
- eq: equals to
|
247
|
+
- not_eq: not equals to
|
248
|
+
- blank: blank (empty/nil/nul)
|
249
|
+
- not_blank: not blank (empty/nil/null)
|
250
|
+
- lt: less than (value converts to float)
|
251
|
+
- lte: less than or equal to (value converts to float)
|
252
|
+
- gt: greater than (value converts to float)
|
253
|
+
- gte: greater than or equal to (value converts to float)
|
254
|
+
|
255
|
+
NOTE: PREDICATES CURRENTLY DO NOT WORK FOR THE OLD DATAMAPPER ADAPTER
|
256
|
+
|
257
|
+
#### Predicate Example
|
258
|
+
```ruby
|
259
|
+
class Post::Finder < Trailblazer::Finder
|
260
|
+
features Predicate
|
261
|
+
|
262
|
+
# Specify the fields you want predicates enabled for, mind you these fields need to exist on your entity_type
|
263
|
+
predicates_for :name, :category_name
|
264
|
+
|
265
|
+
filter_by :name
|
266
|
+
filter_by :published
|
267
|
+
filter_by :category_name
|
268
|
+
|
269
|
+
# per page defaults to 25 (so not required)
|
270
|
+
per_page 10
|
271
|
+
|
272
|
+
# Minimum items per page (not required)
|
273
|
+
min_per_page 5
|
274
|
+
|
275
|
+
# Maximum items per page (not required)
|
276
|
+
max_per_page 100
|
277
|
+
end
|
278
|
+
```
|
279
|
+
|
280
|
+
This feature extends the result[:finder] object with the following methods
|
281
|
+
```ruby
|
282
|
+
# accessing filters
|
283
|
+
.name # => name filter
|
284
|
+
.created_at # => created at filter
|
285
|
+
|
286
|
+
# Predicate filters
|
287
|
+
.name_eq # => name equals filter
|
288
|
+
.name_not_eq # => name not equals filter
|
289
|
+
.name_blank # => name blank filter
|
290
|
+
.name_not_blank # => name not blank filter
|
291
|
+
.name_lt # => name less than filter (converts value to float)
|
292
|
+
.name_lte # => name less than or equal to filter (converts value to float)
|
293
|
+
.name_gt # => name greater than filter (converts value to float)
|
294
|
+
.name_gte # => name greater than or equal to filter (converts value to float)
|
295
|
+
.category_name_eq # => category name equals filter
|
296
|
+
.category_name_not_eq # => category name not equals filter
|
297
|
+
.category_name_blank # => category name blank filter
|
298
|
+
.category_name_not_blank # => category name not blank filter
|
299
|
+
.category_name_lt # => category name less than filter (converts value to float)
|
300
|
+
.category_name_lte # => category name less than or equal to filter (converts value to float)
|
301
|
+
.category_name_gt # => category name greater than filter (converts value to float)
|
302
|
+
.category_name_gte # => category name greater than or equal to filter (converts value to float)
|
303
|
+
|
304
|
+
# accessing results
|
305
|
+
.count # => number of found results
|
306
|
+
.results? # => are there any results found
|
307
|
+
.results # => fetched results
|
308
|
+
.all # => if needed, use it to get dataset (sequel for example requires you use it in some cases)
|
309
|
+
|
310
|
+
# params for url generations
|
311
|
+
.params # => filter values
|
312
|
+
.params published: false # => overwrites the 'published' filter
|
313
|
+
```
|
242
314
|
|
243
|
-
|
315
|
+
### Paging
|
316
|
+
Really simple pagination feature, which uses the plain ```.limit``` and ```.offset``` methods.
|
244
317
|
|
245
318
|
#### Paging Example
|
246
319
|
```ruby
|
@@ -268,10 +341,8 @@ This feature extends the result[:finder] object with the following methods
|
|
268
341
|
.results # => paginated page results
|
269
342
|
```
|
270
343
|
|
271
|
-
### Sorting
|
272
|
-
|
273
|
-
Fixing the pain of dealing with sorting attributes and directions.
|
274
|
-
|
344
|
+
### Sorting
|
345
|
+
Really simple sorting feature, fixing the pain of dealing with sorting attributes and directions. For the moment only sorting by a single attribute works, we're working on making it possible to sort by multiple attributes.
|
275
346
|
|
276
347
|
#### Sorting Example
|
277
348
|
```ruby
|
data/lib/trailblazer/finder.rb
CHANGED
@@ -9,11 +9,14 @@ require 'trailblazer/finder/utils/params'
|
|
9
9
|
require 'trailblazer/finder/utils/parse'
|
10
10
|
require 'trailblazer/finder/utils/string'
|
11
11
|
require 'trailblazer/finder/utils/extra'
|
12
|
+
require 'trailblazer/finder/utils/splitter'
|
13
|
+
require 'trailblazer/finder/utils/deep_locate'
|
12
14
|
require 'trailblazer/finder/base'
|
13
15
|
require 'trailblazer/finder/find'
|
14
16
|
require 'trailblazer/finder/filter'
|
15
17
|
require 'trailblazer/finder/features'
|
16
18
|
require 'trailblazer/finder/adapters'
|
19
|
+
require 'trailblazer/finder/predicates'
|
17
20
|
|
18
21
|
# :nocov:
|
19
22
|
require 'trailblazer/operation/finder' if Gem.loaded_specs.key?('trailblazer')
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'trailblazer/finder/adapters/active_record/paging'
|
2
2
|
require 'trailblazer/finder/adapters/active_record/sorting'
|
3
|
+
require 'trailblazer/finder/adapters/active_record/predicates'
|
3
4
|
|
4
5
|
module Trailblazer
|
5
6
|
class Finder
|
@@ -8,6 +9,9 @@ module Trailblazer
|
|
8
9
|
module ActiveRecord
|
9
10
|
def self.included(base)
|
10
11
|
base.extend ClassMethods
|
12
|
+
base.instance_eval do
|
13
|
+
include ActiveRecord::Predicates if defined?(Features::Predicate::ClassMethods)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
module ClassMethods
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
class Finder
|
3
|
+
module Adapters
|
4
|
+
module ActiveRecord
|
5
|
+
# ActiveRecord - Predicate Adapter
|
6
|
+
module Predicates
|
7
|
+
def not_eq(attribute, value, entity_type)
|
8
|
+
entity_type.where.not(attribute => value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def eq(attribute, value, entity_type)
|
12
|
+
entity_type.where(attribute => value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def blank(attribute, _value, entity_type)
|
16
|
+
entity_type.where(attribute.to_sym => [nil, ''])
|
17
|
+
end
|
18
|
+
|
19
|
+
def not_blank(attribute, _value, entity_type)
|
20
|
+
entity_type.where.not(attribute.to_sym => [nil, ''])
|
21
|
+
end
|
22
|
+
|
23
|
+
def gt(attribute, value, entity_type)
|
24
|
+
entity_type.where(["#{attribute} > ?", value.to_f])
|
25
|
+
end
|
26
|
+
|
27
|
+
def gte(attribute, value, entity_type)
|
28
|
+
entity_type.where(["#{attribute} >= ?", value.to_f])
|
29
|
+
end
|
30
|
+
|
31
|
+
def lt(attribute, value, entity_type)
|
32
|
+
entity_type.where(["#{attribute} < ?", value.to_f])
|
33
|
+
end
|
34
|
+
|
35
|
+
def lte(attribute, value, entity_type)
|
36
|
+
entity_type.where(["#{attribute} <= ?", value.to_f])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|