talent_scout 1.0.1 → 2.0.0
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 +4 -4
- data/README.md +43 -48
- data/Rakefile +1 -20
- data/lib/talent_scout/controller.rb +9 -11
- data/lib/talent_scout/criteria.rb +2 -1
- data/lib/talent_scout/model_search.rb +89 -89
- data/lib/talent_scout/version.rb +1 -1
- metadata +9 -87
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5fd5304fedac4c3a0cddd986f91cbc7a6bbe03e31948a1abdbdeaf58b7e16bf
|
|
4
|
+
data.tar.gz: 55e50c5eb694771e367f9741d79ae5510adcf48c05fdd62252895a31157730d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4ce41f71c08cc80a4acaf3ed9b4b382b3132966f8656ee7b817751e71abdfcc5571234bc66b93f07e022545be4e939f0317b227b9d662732f5f8916a7a2a967
|
|
7
|
+
data.tar.gz: dcc4a74c840c6cb423865794008496788af7bbcdfa5fc8d4a3096bf85448efcba553af1c4e1045d62866a38b4a4ec63f8791a25f4e68c5879b43054893b68274
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# talent_scout
|
|
1
|
+
# talent_scout
|
|
2
2
|
|
|
3
3
|
Model-backed searches in Rails. A whiz-bang example:
|
|
4
4
|
|
|
@@ -83,13 +83,13 @@ In the above example:
|
|
|
83
83
|
|
|
84
84
|
* The `PostSearch` class handles the responsibility of searching for
|
|
85
85
|
`Post` models. It can apply any combination of its defined criteria,
|
|
86
|
-
automatically ignoring missing or
|
|
87
|
-
order the results by one of its defined orders, in either
|
|
88
|
-
descending direction.
|
|
86
|
+
automatically ignoring missing, blank, or invalid input values. It
|
|
87
|
+
can also order the results by one of its defined orders, in either
|
|
88
|
+
ascending or descending direction.
|
|
89
89
|
* `PostsController#index` uses the `model_search` helper to construct a
|
|
90
|
-
`PostSearch
|
|
91
|
-
in the view. The search results are also assigned to a
|
|
92
|
-
use in the view.
|
|
90
|
+
`PostSearch` instance, and assigns it to the `@search` variable for
|
|
91
|
+
later use in the view. The search results are also assigned to a
|
|
92
|
+
variable for use in the view.
|
|
93
93
|
* The view uses Rails' stock form builder to build a search form with
|
|
94
94
|
the `@search` variable. The `link_to_search` helper is used to create
|
|
95
95
|
links in the table header which sort the results. Note that the
|
|
@@ -97,13 +97,13 @@ In the above example:
|
|
|
97
97
|
`@search` unmodified.
|
|
98
98
|
|
|
99
99
|
For a detailed explanation of the methods used in this example, see
|
|
100
|
-
the [API documentation](
|
|
100
|
+
the [API documentation](https://www.rubydoc.info/gems/talent_scout/).
|
|
101
101
|
|
|
102
102
|
|
|
103
|
-
## Search
|
|
103
|
+
## Search Classes
|
|
104
104
|
|
|
105
|
-
You can use the `talent_scout:search` generator to generate
|
|
106
|
-
|
|
105
|
+
You can use the `talent_scout:search` generator to generate a model
|
|
106
|
+
search class definition. For example,
|
|
107
107
|
|
|
108
108
|
```bash
|
|
109
109
|
$ rails generate talent_scout:search post
|
|
@@ -116,14 +116,14 @@ class PostSearch < TalentScout::ModelSearch
|
|
|
116
116
|
end
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Search
|
|
120
|
-
model class is inferred from the search
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
Search classes inherit from `TalentScout::ModelSearch`. Their target
|
|
120
|
+
model class is inferred from the search class name. For example,
|
|
121
|
+
`PostSearch` will search for `Post` models by default. To override this
|
|
122
|
+
inference, use `ModelSearch::model_class=`:
|
|
123
123
|
|
|
124
124
|
```ruby
|
|
125
125
|
class EmployeeSearch < TalentScout::ModelSearch
|
|
126
|
-
self.model_class = Person #
|
|
126
|
+
self.model_class = Person # search for Person models instead of `Employee`
|
|
127
127
|
end
|
|
128
128
|
```
|
|
129
129
|
|
|
@@ -153,7 +153,8 @@ end
|
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Note that explicit query blocks are evaluated in the context of the
|
|
156
|
-
model's `ActiveRecord::Relation`, just
|
|
156
|
+
model's `ActiveRecord::Relation`, just like Active Record `scope` blocks
|
|
157
|
+
are.
|
|
157
158
|
|
|
158
159
|
|
|
159
160
|
#### Criteria Type
|
|
@@ -186,7 +187,7 @@ Available criteria types are the same as for Active Model attributes:
|
|
|
186
187
|
`:integer`, `:string`, `:time`, plus any custom types you define.
|
|
187
188
|
|
|
188
189
|
An additional convenience type is also available: `:void`. The `:void`
|
|
189
|
-
type
|
|
190
|
+
type typecasts like `:boolean`, but prevents the criteria from being
|
|
190
191
|
applied when the typecasted value is falsey. For example:
|
|
191
192
|
|
|
192
193
|
```ruby
|
|
@@ -337,8 +338,8 @@ PostSearch.new(order: :title)
|
|
|
337
338
|
PostSearch.new(order: :category)
|
|
338
339
|
```
|
|
339
340
|
|
|
340
|
-
Only one order can be applied at a time, but an order can
|
|
341
|
-
|
|
341
|
+
Only one order can be applied at a time, but an order can comprise
|
|
342
|
+
multiple columns:
|
|
342
343
|
|
|
343
344
|
```ruby
|
|
344
345
|
class PostSearch < TalentScout::ModelSearch
|
|
@@ -391,7 +392,7 @@ end
|
|
|
391
392
|
PostSearch.new(order: :category).toggle_order(:category)
|
|
392
393
|
```
|
|
393
394
|
|
|
394
|
-
To circumvent this behavior
|
|
395
|
+
To circumvent this behavior and instead fix a column in a static
|
|
395
396
|
direction, append `" ASC"` or `" DESC"` to the column name:
|
|
396
397
|
|
|
397
398
|
```ruby
|
|
@@ -465,7 +466,7 @@ PostSearch.new(order: :title)
|
|
|
465
466
|
```
|
|
466
467
|
|
|
467
468
|
Note that the default order direction can be either ascending or
|
|
468
|
-
descending
|
|
469
|
+
descending by specifying `default: :asc` or `default: :desc`,
|
|
469
470
|
respectively. Also, just as only one order can be applied at a time,
|
|
470
471
|
only one order can be designated default.
|
|
471
472
|
|
|
@@ -513,10 +514,9 @@ class EmployeesController < ApplicationController
|
|
|
513
514
|
end
|
|
514
515
|
```
|
|
515
516
|
|
|
516
|
-
In these examples, the search object is stored in
|
|
517
|
-
the view
|
|
518
|
-
|
|
519
|
-
can be applied to `@search.results`.
|
|
517
|
+
In these examples, the search object is stored in `@search` for use in
|
|
518
|
+
the view. Note that `@search.results` returns an `ActiveRecord::Relation`,
|
|
519
|
+
so any additional scoping, such as pagination, can be applied.
|
|
520
520
|
|
|
521
521
|
|
|
522
522
|
## Search Forms
|
|
@@ -539,7 +539,7 @@ object:
|
|
|
539
539
|
<% end %>
|
|
540
540
|
```
|
|
541
541
|
|
|
542
|
-
Notice the `method: :get` argument to `form_with
|
|
542
|
+
**Notice the `method: :get` argument to `form_with`. This is required.**
|
|
543
543
|
|
|
544
544
|
Form fields will be populated with the criteria input (or default)
|
|
545
545
|
values of the same name from `@search`. Type-appropriate form fields
|
|
@@ -562,7 +562,7 @@ method:
|
|
|
562
562
|
<%= link_to_search "Sort by title", @search.toggle_order(:title, :asc) %>
|
|
563
563
|
```
|
|
564
564
|
|
|
565
|
-
The link will automatically point to current controller and current
|
|
565
|
+
The link will automatically point to the current controller and current
|
|
566
566
|
action, with query parameters from the given search object. To link to
|
|
567
567
|
a different controller or action, pass an options Hash in place of the
|
|
568
568
|
search object:
|
|
@@ -597,9 +597,9 @@ rendering the view.
|
|
|
597
597
|
One such method is `ModelSearch#toggle_order`, which was shown in
|
|
598
598
|
[previous examples](#order-direction). Remember that `toggle_order` is
|
|
599
599
|
a builder-style method that does not modify the search object. Instead,
|
|
600
|
-
it duplicates the search object, and sets the order on the new
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
it duplicates the search object, and sets the order on the new object.
|
|
601
|
+
Such behavior is suitable to generating links to multiple variants of a
|
|
602
|
+
search, such as sort links in table column headers.
|
|
603
603
|
|
|
604
604
|
|
|
605
605
|
### `ModelSearch#with` and `ModelSearch#without`
|
|
@@ -641,8 +641,7 @@ PostSearch.new(title: "Maaaaath!", published: false).without(:published)
|
|
|
641
641
|
|
|
642
642
|
Another helpful method is `ModelSearch#each_choice`, which will iterate
|
|
643
643
|
over the defined choices for a given criteria. This can be used to
|
|
644
|
-
generate links to variants of a search
|
|
645
|
-
select box:
|
|
644
|
+
generate links to variants of a search:
|
|
646
645
|
|
|
647
646
|
```ruby
|
|
648
647
|
class PostSearch < TalentScout::ModelSearch
|
|
@@ -657,6 +656,12 @@ end
|
|
|
657
656
|
<% end %>
|
|
658
657
|
```
|
|
659
658
|
|
|
659
|
+
Notice that if the block passed to `each_choice` accepts two arguments,
|
|
660
|
+
the 2nd argument will indicate if the choice is currently chosen.
|
|
661
|
+
|
|
662
|
+
If no block is passed to `each_choice`, it will return an `Enumerator`.
|
|
663
|
+
This can be used to generate options for a select box:
|
|
664
|
+
|
|
660
665
|
```html+erb
|
|
661
666
|
<%= form_with model: @search, local: true, method: :get do |form| %>
|
|
662
667
|
<%= form.select :category, @search.each_choice(:category) %>
|
|
@@ -664,10 +669,6 @@ end
|
|
|
664
669
|
<% end %>
|
|
665
670
|
```
|
|
666
671
|
|
|
667
|
-
If the block passed to `each_choice` accepts two arguments, the 2nd
|
|
668
|
-
argument will indicate if the choice is currently chosen. If no block
|
|
669
|
-
is passed to `each_choice`, it will return an `Enumerator`.
|
|
670
|
-
|
|
671
672
|
The `each_choice` method can also be invoked with `:order`. Doing so
|
|
672
673
|
will iterate over each direction of each defined order, yielding the
|
|
673
674
|
appropriate labels including direction suffix:
|
|
@@ -723,19 +724,13 @@ in the Hash, at most, will be non-`nil`.
|
|
|
723
724
|
|
|
724
725
|
## Installation
|
|
725
726
|
|
|
726
|
-
Add
|
|
727
|
-
|
|
728
|
-
```ruby
|
|
729
|
-
gem "talent_scout"
|
|
730
|
-
```
|
|
731
|
-
|
|
732
|
-
Then execute:
|
|
727
|
+
Add the gem to your Gemfile:
|
|
733
728
|
|
|
734
729
|
```bash
|
|
735
|
-
$ bundle
|
|
730
|
+
$ bundle add talent_scout
|
|
736
731
|
```
|
|
737
732
|
|
|
738
|
-
And
|
|
733
|
+
And run the installation generator:
|
|
739
734
|
|
|
740
735
|
```bash
|
|
741
736
|
$ rails generate talent_scout:install
|
|
@@ -744,9 +739,9 @@ $ rails generate talent_scout:install
|
|
|
744
739
|
|
|
745
740
|
## Contributing
|
|
746
741
|
|
|
747
|
-
Run `
|
|
742
|
+
Run `bin/test` to run the tests.
|
|
748
743
|
|
|
749
744
|
|
|
750
745
|
## License
|
|
751
746
|
|
|
752
|
-
[MIT License](
|
|
747
|
+
[MIT License](MIT-LICENSE)
|
data/Rakefile
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
require 'bundler/setup'
|
|
3
|
-
rescue LoadError
|
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
require 'yard'
|
|
8
|
-
|
|
9
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
|
10
|
-
end
|
|
1
|
+
require 'bundler/setup'
|
|
11
2
|
|
|
12
3
|
require 'bundler/gem_tasks'
|
|
13
|
-
|
|
14
|
-
require 'rake/testtask'
|
|
15
|
-
|
|
16
|
-
Rake::TestTask.new(:test) do |t|
|
|
17
|
-
t.libs << 'test'
|
|
18
|
-
t.test_files = FileList['test/**/*_test.rb'].exclude('test/tmp/**/*')
|
|
19
|
-
t.verbose = false
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
task default: :test
|
|
@@ -5,9 +5,9 @@ module TalentScout
|
|
|
5
5
|
module ClassMethods
|
|
6
6
|
# Returns the controller model search class. Defaults to a class
|
|
7
7
|
# corresponding to the singular form of the controller name. The
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
8
|
+
# class can be set with {model_search_class=}. If the class has
|
|
9
|
+
# not been set and the default class does not exist, a +NameError+
|
|
10
|
+
# will be raised.
|
|
11
11
|
#
|
|
12
12
|
# @example
|
|
13
13
|
# class PostsController < ApplicationController
|
|
@@ -17,8 +17,7 @@ module TalentScout
|
|
|
17
17
|
#
|
|
18
18
|
# @return [Class<TalentScout::ModelSearch>]
|
|
19
19
|
# @raise [NameError]
|
|
20
|
-
# if the model search class
|
|
21
|
-
# class does not exist
|
|
20
|
+
# if the model search class does not exist
|
|
22
21
|
def model_search_class
|
|
23
22
|
@model_search_class ||= "#{controller_path.classify}Search".constantize
|
|
24
23
|
end
|
|
@@ -26,14 +25,13 @@ module TalentScout
|
|
|
26
25
|
# Sets the controller model search class. See {model_search_class}.
|
|
27
26
|
#
|
|
28
27
|
# @param klass [Class<TalentScout::ModelSearch>]
|
|
29
|
-
# @return [
|
|
28
|
+
# @return [klass]
|
|
30
29
|
def model_search_class=(klass)
|
|
31
30
|
@model_search_class = klass
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
# Similar to {model_search_class}, but returns nil instead of
|
|
35
|
-
# raising an error when the
|
|
36
|
-
# class does not exist.
|
|
34
|
+
# raising an error when the model search class does not exist.
|
|
37
35
|
#
|
|
38
36
|
# @return [Class<TalentScout::ModelSearch>, nil]
|
|
39
37
|
def model_search_class?
|
|
@@ -46,9 +44,9 @@ module TalentScout
|
|
|
46
44
|
end
|
|
47
45
|
end
|
|
48
46
|
|
|
49
|
-
# Instantiates {ClassMethods#model_search_class}
|
|
50
|
-
# request's query params. If that class does not
|
|
51
|
-
# +NameError+ will be raised.
|
|
47
|
+
# Instantiates {ClassMethods#model_search_class ::model_search_class}
|
|
48
|
+
# using the current request's query params. If that class does not
|
|
49
|
+
# exist, a +NameError+ will be raised.
|
|
52
50
|
#
|
|
53
51
|
# @return [TalentScout::ModelSearch]
|
|
54
52
|
# @raise [NameError]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module TalentScout
|
|
2
2
|
# @!visibility private
|
|
3
3
|
class Criteria
|
|
4
|
+
SYMBOL_TO_PROC_ARITY = :to_s.to_proc.arity
|
|
4
5
|
|
|
5
6
|
attr_reader :names, :allow_nil, :block
|
|
6
7
|
|
|
@@ -14,7 +15,7 @@ module TalentScout
|
|
|
14
15
|
if applicable?(attribute_set)
|
|
15
16
|
if block
|
|
16
17
|
block_args = names.map{|name| attribute_set[name].value }
|
|
17
|
-
if block.arity ==
|
|
18
|
+
if block.arity == SYMBOL_TO_PROC_ARITY # assume block is from Symbol#to_proc
|
|
18
19
|
scope.instance_exec(scope, *block_args, &block)
|
|
19
20
|
else
|
|
20
21
|
scope.instance_exec(*block_args, &block)
|
|
@@ -7,10 +7,10 @@ module TalentScout
|
|
|
7
7
|
extend ActiveModel::Translation
|
|
8
8
|
|
|
9
9
|
# Returns the model class that the search targets. Defaults to a
|
|
10
|
-
# class with same name
|
|
11
|
-
# suffix. The
|
|
12
|
-
#
|
|
13
|
-
#
|
|
10
|
+
# class with same name as the search class, minus the "Search"
|
|
11
|
+
# suffix. The class can be set with {model_class=}. If the class
|
|
12
|
+
# has not been set and the default class does not exist, a
|
|
13
|
+
# +NameError+ will be raised.
|
|
14
14
|
#
|
|
15
15
|
# @example Default behavior
|
|
16
16
|
# class PostSearch < TalentScout::ModelSearch
|
|
@@ -27,8 +27,7 @@ module TalentScout
|
|
|
27
27
|
#
|
|
28
28
|
# @return [Class]
|
|
29
29
|
# @raise [NameError]
|
|
30
|
-
# if the model class
|
|
31
|
-
# not exist
|
|
30
|
+
# if the model class does not exist
|
|
32
31
|
def self.model_class
|
|
33
32
|
@model_class ||= self.superclass == ModelSearch ?
|
|
34
33
|
self.name.chomp("Search").constantize : self.superclass.model_class
|
|
@@ -37,7 +36,7 @@ module TalentScout
|
|
|
37
36
|
# Sets the model class that the search targets. See {model_class}.
|
|
38
37
|
#
|
|
39
38
|
# @param model_class [Class]
|
|
40
|
-
# @return [
|
|
39
|
+
# @return [model_class]
|
|
41
40
|
def self.model_class=(model_class)
|
|
42
41
|
@model_class = model_class
|
|
43
42
|
end
|
|
@@ -66,7 +65,7 @@ module TalentScout
|
|
|
66
65
|
# end
|
|
67
66
|
#
|
|
68
67
|
# class PostSearch < TalentScout::ModelSearch
|
|
69
|
-
# default_scope
|
|
68
|
+
# default_scope &:published
|
|
70
69
|
# end
|
|
71
70
|
#
|
|
72
71
|
# PostSearch.new.results # == Post.published
|
|
@@ -78,36 +77,36 @@ module TalentScout
|
|
|
78
77
|
criteria_list.insert(i, Criteria.new([], true, &block))
|
|
79
78
|
end
|
|
80
79
|
|
|
81
|
-
# Defines criteria
|
|
82
|
-
#
|
|
83
|
-
# when building a search form.
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
# the typecasted value is falsey.
|
|
80
|
+
# Defines criteria that can be incorporated into a search. The
|
|
81
|
+
# criteria will have a corresponding attribute on the search object
|
|
82
|
+
# that can be used when building a search form. The type of the
|
|
83
|
+
# attribute can be specified, just as with Active Model attributes,
|
|
84
|
+
# and the attribute value will be typecasted before the criteria is
|
|
85
|
+
# incorporated. Supported types are the same as Active Model (e.g.
|
|
86
|
+
# +:string+, +:boolean+, +:integer+, etc). The default type is
|
|
87
|
+
# +:string+. An additional +:void+ type is also supported, which
|
|
88
|
+
# typecasts like the +:boolean+ type, but prevents the criteria
|
|
89
|
+
# from being incorporated if the typecasted value is falsey.
|
|
92
90
|
#
|
|
93
91
|
# Alternatively, instead of a type, an Array or Hash of +choices+
|
|
94
|
-
# can be specified, and the criteria will be
|
|
95
|
-
#
|
|
92
|
+
# can be specified, and the criteria will be incorporated only if
|
|
93
|
+
# the attribute value matches one of the choices.
|
|
96
94
|
#
|
|
97
95
|
# Active Model +attribute_options+ can also be specified. Most
|
|
98
|
-
# notably, the +:default+ option
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
#
|
|
108
|
-
#
|
|
109
|
-
#
|
|
110
|
-
#
|
|
96
|
+
# notably, the +:default+ option can specify a default value for the
|
|
97
|
+
# criteria to operate on. If a default value is not specified, the
|
|
98
|
+
# criteria will be incorporated only if the attribute value is set.
|
|
99
|
+
#
|
|
100
|
+
# If no block is given, the criteria will be incorporated as a
|
|
101
|
+
# +where+ clause using the criteria name and typecasted attribute
|
|
102
|
+
# value.
|
|
103
|
+
#
|
|
104
|
+
# If a block is given, it will be passed the typecasted attribute
|
|
105
|
+
# value, and it will be evaluated in the context of an
|
|
106
|
+
# +ActiveRecord::Relation+, like Active Record +scope+ blocks are.
|
|
107
|
+
# The block should return an +ActiveRecord::Relation+. The block
|
|
108
|
+
# may also return nil, in which case the criteria will not be
|
|
109
|
+
# incorporated.
|
|
111
110
|
#
|
|
112
111
|
# As a convenient shorthand, Active Record scopes which have been
|
|
113
112
|
# defined on the {model_class} can be used directly as criteria
|
|
@@ -115,7 +114,7 @@ module TalentScout
|
|
|
115
114
|
# the criteria block.
|
|
116
115
|
#
|
|
117
116
|
#
|
|
118
|
-
# @example
|
|
117
|
+
# @example Without a block
|
|
119
118
|
# class PostSearch < TalentScout::ModelSearch
|
|
120
119
|
# criteria :title
|
|
121
120
|
# end
|
|
@@ -123,7 +122,7 @@ module TalentScout
|
|
|
123
122
|
# PostSearch.new(title: "FOO").results # == Post.where(title: "FOO")
|
|
124
123
|
#
|
|
125
124
|
#
|
|
126
|
-
# @example
|
|
125
|
+
# @example With a block
|
|
127
126
|
# class PostSearch < TalentScout::ModelSearch
|
|
128
127
|
# criteria :title do |string|
|
|
129
128
|
# where("title LIKE ?", "%#{string}%")
|
|
@@ -209,33 +208,33 @@ module TalentScout
|
|
|
209
208
|
# PostSearch.new(within_days: 2).results # == Post.where("created_at >= ?", 2.days.ago)
|
|
210
209
|
#
|
|
211
210
|
#
|
|
212
|
-
# @overload criteria(
|
|
213
|
-
# @param
|
|
211
|
+
# @overload criteria(name, type = :string, **attribute_options)
|
|
212
|
+
# @param name [String, Symbol]
|
|
214
213
|
# @param type [Symbol, ActiveModel::Type]
|
|
215
214
|
# @param attribute_options [Hash]
|
|
216
215
|
# @option attribute_options :default [Object]
|
|
217
|
-
# @yieldparam value [Object]
|
|
218
|
-
# @yieldreturn [ActiveRecord::Relation, nil]
|
|
219
216
|
#
|
|
220
|
-
# @overload criteria(
|
|
221
|
-
# @param
|
|
217
|
+
# @overload criteria(name, type = :string, **attribute_options, &block)
|
|
218
|
+
# @param name [String, Symbol]
|
|
222
219
|
# @param type [Symbol, ActiveModel::Type]
|
|
223
220
|
# @param attribute_options [Hash]
|
|
224
221
|
# @option attribute_options :default [Object]
|
|
222
|
+
# @yieldparam value [Object]
|
|
223
|
+
# @yieldreturn [ActiveRecord::Relation, nil]
|
|
225
224
|
#
|
|
226
|
-
# @overload criteria(
|
|
227
|
-
# @param
|
|
228
|
-
# @param choices [Array<String>, Array<Symbol>, Hash
|
|
225
|
+
# @overload criteria(name, choices:, **attribute_options)
|
|
226
|
+
# @param name [String, Symbol]
|
|
227
|
+
# @param choices [Array<String>, Array<Symbol>, Hash{String => Object}, Hash{Symbol => Object}]
|
|
229
228
|
# @param attribute_options [Hash]
|
|
230
229
|
# @option attribute_options :default [Object]
|
|
231
|
-
# @yieldparam value [Object]
|
|
232
230
|
# @yieldreturn [ActiveRecord::Relation, nil]
|
|
233
231
|
#
|
|
234
|
-
# @overload criteria(
|
|
235
|
-
# @param
|
|
236
|
-
# @param choices [Array<String>, Array<Symbol>, Hash
|
|
232
|
+
# @overload criteria(name, choices:, **attribute_options, &block)
|
|
233
|
+
# @param name [String, Symbol]
|
|
234
|
+
# @param choices [Array<String>, Array<Symbol>, Hash{String => Object}, Hash{Symbol => Object}]
|
|
237
235
|
# @param attribute_options [Hash]
|
|
238
236
|
# @option attribute_options :default [Object]
|
|
237
|
+
# @yieldparam value [Object]
|
|
239
238
|
# @yieldreturn [ActiveRecord::Relation, nil]
|
|
240
239
|
#
|
|
241
240
|
# @return [void]
|
|
@@ -260,7 +259,7 @@ module TalentScout
|
|
|
260
259
|
criteria_list << crit
|
|
261
260
|
|
|
262
261
|
crit.names.each do |name|
|
|
263
|
-
attribute name, type, attribute_options
|
|
262
|
+
attribute name, type, **attribute_options
|
|
264
263
|
|
|
265
264
|
# HACK FormBuilder#select uses normal attribute readers instead
|
|
266
265
|
# of `*_before_type_cast` attribute readers. This breaks value
|
|
@@ -273,24 +272,24 @@ module TalentScout
|
|
|
273
272
|
end
|
|
274
273
|
end
|
|
275
274
|
|
|
276
|
-
# Defines
|
|
277
|
-
# one order can be
|
|
278
|
-
#
|
|
279
|
-
# +name+ is taken as its column.
|
|
280
|
-
#
|
|
281
|
-
#
|
|
282
|
-
# by appending
|
|
283
|
-
# default, these suffixes are +".asc"+ and +".desc"+, but they
|
|
284
|
-
# be overridden in the order definition using the +:asc_suffix+
|
|
285
|
-
# +:desc_suffix+ options, respectively.
|
|
286
|
-
#
|
|
287
|
-
#
|
|
275
|
+
# Defines a result order that can be incorporated into a search.
|
|
276
|
+
# Only one order can be incorporated at a time, but an order can
|
|
277
|
+
# comprise multiple columns. If no columns are specified, the
|
|
278
|
+
# order's +name+ is taken as its column.
|
|
279
|
+
#
|
|
280
|
+
# An order can be incorporated in either ascending or descending
|
|
281
|
+
# direction by appending an appropriate suffix to the order value.
|
|
282
|
+
# By default, these suffixes are +".asc"+ and +".desc"+, but they
|
|
283
|
+
# can be overridden in the order definition using the +:asc_suffix+
|
|
284
|
+
# and +:desc_suffix+ options, respectively.
|
|
285
|
+
#
|
|
286
|
+
# The order direction will affect all columns of the order, unless
|
|
288
287
|
# a column explicitly specifies +"ASC"+ or +"DESC"+, in which case
|
|
289
288
|
# that column will stay fixed in its specified direction.
|
|
290
289
|
#
|
|
291
|
-
# To
|
|
292
|
-
# +:default+ option
|
|
293
|
-
#
|
|
290
|
+
# To designate the order as the default result order, use the
|
|
291
|
+
# +:default+ option. (Note that only one order can be designated as
|
|
292
|
+
# the default order.)
|
|
294
293
|
#
|
|
295
294
|
# @see toggle_order
|
|
296
295
|
#
|
|
@@ -350,20 +349,21 @@ module TalentScout
|
|
|
350
349
|
# PostSearch.new(order: :title).results # == Post.order("title")
|
|
351
350
|
#
|
|
352
351
|
#
|
|
353
|
-
# @
|
|
354
|
-
#
|
|
355
|
-
#
|
|
356
|
-
#
|
|
357
|
-
#
|
|
358
|
-
#
|
|
359
|
-
#
|
|
352
|
+
# @overload order(name, columns = [name], **options)
|
|
353
|
+
# @param name [String, Symbol]
|
|
354
|
+
# @param columns [Array<String>, Array<Symbol>]
|
|
355
|
+
# @param options [Hash]
|
|
356
|
+
# @option options :default [Boolean, :asc, :desc] (false)
|
|
357
|
+
# @option options :asc_suffix [String] (".asc")
|
|
358
|
+
# @option options :desc_suffix [String] (".desc")
|
|
359
|
+
# @return [void]
|
|
360
360
|
def self.order(name, columns = nil, default: false, **options)
|
|
361
|
-
definition = OrderDefinition.new(name, columns, options)
|
|
361
|
+
definition = OrderDefinition.new(name, columns, **options)
|
|
362
362
|
|
|
363
363
|
if !attribute_types.fetch("order", nil).equal?(order_type) || default
|
|
364
364
|
criteria_options = default ? { default: definition.choice_for_direction(default) } : {}
|
|
365
365
|
criteria_list.reject!{|crit| crit.names == ["order"] }
|
|
366
|
-
criteria "order", order_type, criteria_options, &:order
|
|
366
|
+
criteria "order", order_type, **criteria_options, &:order
|
|
367
367
|
end
|
|
368
368
|
|
|
369
369
|
order_type.add_definition(definition)
|
|
@@ -376,7 +376,7 @@ module TalentScout
|
|
|
376
376
|
# ignored. This behavior prevents empty search form fields from
|
|
377
377
|
# affecting search results.
|
|
378
378
|
#
|
|
379
|
-
# @param params [Hash
|
|
379
|
+
# @param params [Hash{String => Object}, Hash{Symbol => Object}, ActionController::Parameters]
|
|
380
380
|
# @raise [ActiveModel::UnknownAttributeError]
|
|
381
381
|
# if +params+ is a Hash, and it contains an unrecognized key
|
|
382
382
|
def initialize(params = {})
|
|
@@ -416,8 +416,8 @@ module TalentScout
|
|
|
416
416
|
end
|
|
417
417
|
end
|
|
418
418
|
|
|
419
|
-
# Builds a new
|
|
420
|
-
#
|
|
419
|
+
# Builds a new search object with +criteria_values+ merged on top of
|
|
420
|
+
# the subject search object's criteria values.
|
|
421
421
|
#
|
|
422
422
|
# Does not modify the subject search object.
|
|
423
423
|
#
|
|
@@ -433,7 +433,7 @@ module TalentScout
|
|
|
433
433
|
# search.with(category: "tech").results # == Post.where(category: "tech")
|
|
434
434
|
# search.results # == Post.where(category: "math")
|
|
435
435
|
#
|
|
436
|
-
# @param criteria_values [Hash
|
|
436
|
+
# @param criteria_values [Hash{String => Object}, Hash{Symbol => Object}]
|
|
437
437
|
# @return [TalentScout::ModelSearch]
|
|
438
438
|
# @raise [ActiveModel::UnknownAttributeError]
|
|
439
439
|
# if one or more +criteria_values+ keys are invalid
|
|
@@ -441,7 +441,7 @@ module TalentScout
|
|
|
441
441
|
self.class.new(attributes.merge!(criteria_values.stringify_keys))
|
|
442
442
|
end
|
|
443
443
|
|
|
444
|
-
# Builds a new
|
|
444
|
+
# Builds a new search object with the subject search object's
|
|
445
445
|
# criteria values, excluding values specified by +criteria_names+.
|
|
446
446
|
# Default criteria values will still be applied.
|
|
447
447
|
#
|
|
@@ -471,12 +471,12 @@ module TalentScout
|
|
|
471
471
|
self.class.new(attributes.except!(*criteria_names))
|
|
472
472
|
end
|
|
473
473
|
|
|
474
|
-
# Builds a new
|
|
475
|
-
#
|
|
476
|
-
#
|
|
477
|
-
#
|
|
478
|
-
#
|
|
479
|
-
#
|
|
474
|
+
# Builds a new search object with the specified order applied on top
|
|
475
|
+
# of the subject search object's criteria values. If the subject
|
|
476
|
+
# search object already has the specified order applied, the order's
|
|
477
|
+
# direction will be toggled from +:asc+ to +:desc+ or from +:desc+
|
|
478
|
+
# to +:asc+. Otherwise, the specified order will be applied with an
|
|
479
|
+
# +:asc+ direction, overriding any previously applied order.
|
|
480
480
|
#
|
|
481
481
|
# If +direction+ is explicitly specified, that direction will be
|
|
482
482
|
# applied regardless of previously applied direction.
|
|
@@ -510,9 +510,9 @@ module TalentScout
|
|
|
510
510
|
# Iterates over a specified {criteria}'s defined choices. If the
|
|
511
511
|
# given block accepts a 2nd argument, a boolean will be passed
|
|
512
512
|
# indicating whether that choice is currently assigned to the
|
|
513
|
-
# specified criteria.
|
|
513
|
+
# specified criteria attribute.
|
|
514
514
|
#
|
|
515
|
-
#
|
|
515
|
+
# If no block is given, an Enumerator is returned instead.
|
|
516
516
|
#
|
|
517
517
|
# @example With block
|
|
518
518
|
# class PostSearch < TalentScout::ModelSearch
|
|
@@ -577,9 +577,9 @@ module TalentScout
|
|
|
577
577
|
|
|
578
578
|
# Returns a +HashWithIndifferentAccess+ with a key for each defined
|
|
579
579
|
# {order}. Each key's associated value indicates that order's
|
|
580
|
-
# currently applied direction -- +:asc+, +:desc+, or
|
|
580
|
+
# currently applied direction -- +:asc+, +:desc+, or nil if the
|
|
581
581
|
# order is not applied. Note that only one order can be applied at
|
|
582
|
-
# a time, so, at most, one value in the Hash will be non
|
|
582
|
+
# a time, so, at most, one value in the Hash will be non-nil.
|
|
583
583
|
#
|
|
584
584
|
# @example
|
|
585
585
|
# class PostSearch < TalentScout::ModelSearch
|
data/lib/talent_scout/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: talent_scout
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Hefner
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rails
|
|
@@ -16,91 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '8.1'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: sqlite3
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: capybara
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '2.15'
|
|
48
|
-
- - "<"
|
|
49
|
-
- !ruby/object:Gem::Version
|
|
50
|
-
version: '4.0'
|
|
51
|
-
type: :development
|
|
52
|
-
prerelease: false
|
|
53
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
-
requirements:
|
|
55
|
-
- - ">="
|
|
56
|
-
- !ruby/object:Gem::Version
|
|
57
|
-
version: '2.15'
|
|
58
|
-
- - "<"
|
|
59
|
-
- !ruby/object:Gem::Version
|
|
60
|
-
version: '4.0'
|
|
61
|
-
- !ruby/object:Gem::Dependency
|
|
62
|
-
name: webdrivers
|
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
|
64
|
-
requirements:
|
|
65
|
-
- - ">="
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: '0'
|
|
68
|
-
type: :development
|
|
69
|
-
prerelease: false
|
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - ">="
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '0'
|
|
75
|
-
- !ruby/object:Gem::Dependency
|
|
76
|
-
name: yard
|
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - "~>"
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '0.9'
|
|
82
|
-
type: :development
|
|
83
|
-
prerelease: false
|
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
-
requirements:
|
|
86
|
-
- - "~>"
|
|
87
|
-
- !ruby/object:Gem::Version
|
|
88
|
-
version: '0.9'
|
|
89
|
-
- !ruby/object:Gem::Dependency
|
|
90
|
-
name: simple_form
|
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
|
92
|
-
requirements:
|
|
93
|
-
- - "~>"
|
|
94
|
-
- !ruby/object:Gem::Version
|
|
95
|
-
version: '4.0'
|
|
96
|
-
type: :development
|
|
97
|
-
prerelease: false
|
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
-
requirements:
|
|
100
|
-
- - "~>"
|
|
101
|
-
- !ruby/object:Gem::Version
|
|
102
|
-
version: '4.0'
|
|
103
|
-
description:
|
|
25
|
+
version: '8.1'
|
|
104
26
|
email:
|
|
105
27
|
- jonathan@hefner.pro
|
|
106
28
|
executables: []
|
|
@@ -131,8 +53,9 @@ files:
|
|
|
131
53
|
homepage: https://github.com/jonathanhefner/talent_scout
|
|
132
54
|
licenses:
|
|
133
55
|
- MIT
|
|
134
|
-
metadata:
|
|
135
|
-
|
|
56
|
+
metadata:
|
|
57
|
+
source_code_uri: https://github.com/jonathanhefner/talent_scout
|
|
58
|
+
changelog_uri: https://github.com/jonathanhefner/talent_scout/blob/master/CHANGELOG.md
|
|
136
59
|
rdoc_options: []
|
|
137
60
|
require_paths:
|
|
138
61
|
- lib
|
|
@@ -140,15 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
140
63
|
requirements:
|
|
141
64
|
- - ">="
|
|
142
65
|
- !ruby/object:Gem::Version
|
|
143
|
-
version: '
|
|
66
|
+
version: '3.4'
|
|
144
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
68
|
requirements:
|
|
146
69
|
- - ">="
|
|
147
70
|
- !ruby/object:Gem::Version
|
|
148
71
|
version: '0'
|
|
149
72
|
requirements: []
|
|
150
|
-
rubygems_version:
|
|
151
|
-
signing_key:
|
|
73
|
+
rubygems_version: 4.0.10
|
|
152
74
|
specification_version: 4
|
|
153
75
|
summary: Model-backed searches in Rails
|
|
154
76
|
test_files: []
|