pursuit 0.3.0 → 0.3.1
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 +7 -2
- data/lib/pursuit/constants.rb +1 -1
- data/lib/pursuit/search_options.rb +15 -8
- data/spec/pursuit/search_options_spec.rb +11 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5d86e6be4355b96bdaf0d8c02ea680e5cf0f6c3c9f5fdcd3d8e9a20785aad8b
|
4
|
+
data.tar.gz: 310009d659879f97ae8bc9947594533fdb0c11f20702b2bf10e1003c072b4425
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49991dd50ed278c76d9dbc7f0dd8f48a7f41fa7905f284964a27df9bc90a55ad6833a5911b86ed159d4d4c88fc2aac736ac5feb2c1b8469fb9adbf02abca3f49
|
7
|
+
data.tar.gz: 6663dc11f0f6e6adc08f87834d303ed59e0269415132d7c0fdb54d96ee7ca926be69097dd26dd58d0bc836b9a9bf7f8ccfc35fd3e8f9c6976340e52b0719c5b1
|
data/README.md
CHANGED
@@ -26,10 +26,15 @@ class Product < ActiveRecord::Base
|
|
26
26
|
# Attributes can be used for both keyed and unkeyed searching by default, but you can pass either `keyed: false` or
|
27
27
|
# `unkeyed: false` to restrict when the attribute is searched.
|
28
28
|
o.attribute :title
|
29
|
-
o.attribute :description
|
30
29
|
o.attribute :rating, unkeyed: false
|
31
30
|
|
32
|
-
# You can
|
31
|
+
# You can shorten the search keyword by passing the desired search term first, and then the real attribute name
|
32
|
+
# as the second argument.
|
33
|
+
# => "desc*=foo"
|
34
|
+
o.attribute :desc, :description
|
35
|
+
|
36
|
+
# It's also possible to query entirely custom Arel nodes by passing a block which returns the Arel node to query.
|
37
|
+
# You could use this to query a person's full name by concatenating their first and last name columns, for example.
|
33
38
|
o.attribute :title_length, unkeyed: false do
|
34
39
|
Arel::Nodes::NamedFunction.new('LENGTH', [
|
35
40
|
arel_table[:title]
|
data/lib/pursuit/constants.rb
CHANGED
@@ -54,7 +54,7 @@ module Pursuit
|
|
54
54
|
keys.map(&:to_s).uniq
|
55
55
|
end
|
56
56
|
|
57
|
-
# Add a relation to
|
57
|
+
# Add a relation to search.
|
58
58
|
#
|
59
59
|
# @param name [Symbol] The name of the relationship attribute.
|
60
60
|
# @param attribute_names [Splat] The name of the attributes within the relationship to search.
|
@@ -64,15 +64,22 @@ module Pursuit
|
|
64
64
|
nil
|
65
65
|
end
|
66
66
|
|
67
|
-
# Add
|
67
|
+
# Add an attribute to search.
|
68
68
|
#
|
69
|
-
# @param
|
70
|
-
#
|
71
|
-
# @param
|
72
|
-
#
|
69
|
+
# @param term_name [Symbol] The keyed search term (can be an existing attribute, or a custom value when
|
70
|
+
# passing either the `attribute_name` or a block returning an Arel node).
|
71
|
+
# @param attribute_name [Symbol] The attribute name to search (defaults to the keyword, when left blank and no
|
72
|
+
# block is passed).
|
73
|
+
# @param keyed [Boolean] `true` when the attribute should be searchable using a keyed term,
|
74
|
+
# `false` otherwise.
|
75
|
+
# @param unkeyed [Boolean] `true` when the attribute should be searchable using an unkeyed term,
|
76
|
+
# `false` otherwise.
|
77
|
+
# @param block [Proc] A block which returns the Arel node to query against. When left blank, the
|
78
|
+
# matching attribute from `.arel_table` is queried instead.
|
73
79
|
#
|
74
|
-
def attribute(
|
75
|
-
|
80
|
+
def attribute(term_name, attribute_name = nil, keyed: true, unkeyed: true, &block)
|
81
|
+
block ||= -> { record_class.arel_table[attribute_name || term_name] }
|
82
|
+
attributes[term_name] = AttributeOptions.new(keyed, unkeyed, block)
|
76
83
|
nil
|
77
84
|
end
|
78
85
|
end
|
@@ -104,11 +104,20 @@ RSpec.describe Pursuit::SearchOptions do
|
|
104
104
|
expect(search_options.attributes[:description].unkeyed).to eq(true)
|
105
105
|
end
|
106
106
|
|
107
|
-
it 'is expected to
|
107
|
+
it 'is expected to query the #term_name attribute' do
|
108
108
|
attribute
|
109
109
|
expect(search_options.attributes[:description].block.call).to eq(Product.arel_table[:description])
|
110
110
|
end
|
111
111
|
|
112
|
+
context 'when passing the attribute name to search' do
|
113
|
+
subject(:attribute) { search_options.attribute(:desc, :description) }
|
114
|
+
|
115
|
+
it 'is expected to query the #attribute_name attribute' do
|
116
|
+
attribute
|
117
|
+
expect(search_options.attributes[:desc].block.call).to eq(Product.arel_table[:description])
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
112
121
|
context 'when passing :keyed eq false' do
|
113
122
|
subject(:attribute) { search_options.attribute(:description, keyed: false) }
|
114
123
|
|
@@ -130,7 +139,7 @@ RSpec.describe Pursuit::SearchOptions do
|
|
130
139
|
context 'when passing a block' do
|
131
140
|
subject(:attribute) { search_options.attribute(:description, &title_length_node_builder) }
|
132
141
|
|
133
|
-
it 'is expected to
|
142
|
+
it 'is expected to query the result of the passed block' do
|
134
143
|
attribute
|
135
144
|
expect(search_options.attributes[:description].block).to eq(title_length_node_builder)
|
136
145
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pursuit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nialto Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|