searchlight 1.2.2 → 1.2.3
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 +6 -14
- data/CHANGELOG.md +4 -0
- data/lib/searchlight/dsl.rb +10 -2
- data/lib/searchlight/search.rb +2 -4
- data/lib/searchlight/version.rb +1 -1
- data/spec/searchlight/search_spec.rb +114 -57
- data/spec/support/account_search.rb +0 -8
- data/spec/support/spiffy_account_search.rb +0 -7
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NGRkZDEzZjhkOTJjYTUyZWY3ZDQ4ZGFiNDc2NzE1ZTRhNDNjZjgxNTdiYTdi
|
10
|
-
NDM1ZGRjYjJjMmMwNGM4MjcyNjQ3YjQ3N2IwYzdiZTljZTE5NTM5OTcwNTU0
|
11
|
-
ZDY2YThkYjAyZjEwYzU4ZjM1NGNkNDc4ZDc0Y2JjNjZkZjJjMjU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODM4NGQ4MjI4M2M3NjU3NTA2N2FlYTcwZWIxYmE3ODZmODkzNDdmY2E5ZGI2
|
14
|
-
NTlmMDJkZDgyNzdiNGEyZGFmMWMzOWY4NDg5ZmU5YzBhYWE1NTViYWNmMGIz
|
15
|
-
ZWRhNzMxZDQzNWZjODcwZmZiYzc5MTc0ZmZmMTFlNjU1YTQ4N2I=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 436f93fd15d48ee73339833c09e679d856210c44
|
4
|
+
data.tar.gz: 0234dd6c0dbed8789a3214c10bc05750aa2a7917
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 985d773a7359d271f74b437dcbcd81a031fc79e3177650236f69d06c4e300100b8e88ecd786b3b955fc64d2eed820fae72310f4cb6c9478fc9ba4ce34ad2f4cd
|
7
|
+
data.tar.gz: e72a800936177e5eea6372c02093f04a36bea9daa532e0390e8a5d308c2e03ca774359a78fa0351f2f70c61d132093875002d9e8749a7f063c62e8345f9736dc
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Searchlight does its best to use [semantic versioning](http://semver.org).
|
4
4
|
|
5
|
+
## v1.2.3
|
6
|
+
|
7
|
+
Fix bug introduced in v1.2: setting defaults in `initialize` did not add them to the options hash, which meant they weren't used in searches.
|
8
|
+
|
5
9
|
## v1.2.2
|
6
10
|
|
7
11
|
Gracefully handle being given explicit `nil` in initialization instead of options hash or empty arguments
|
data/lib/searchlight/dsl.rb
CHANGED
@@ -19,9 +19,17 @@ module Searchlight
|
|
19
19
|
include @accessors_module
|
20
20
|
end
|
21
21
|
|
22
|
-
eval_string =
|
23
|
-
eval_string << attribute_names.map { |attribute_name|
|
22
|
+
eval_string = attribute_names.map { |attribute_name|
|
24
23
|
<<-LEPRECHAUN_JUICE
|
24
|
+
def #{attribute_name}=(val)
|
25
|
+
self.options ||= {}
|
26
|
+
self.options[:#{attribute_name}] = val
|
27
|
+
end
|
28
|
+
|
29
|
+
def #{attribute_name}
|
30
|
+
self.options[:#{attribute_name}]
|
31
|
+
end
|
32
|
+
|
25
33
|
def #{attribute_name}?
|
26
34
|
truthy?(public_send("#{attribute_name}"))
|
27
35
|
end
|
data/lib/searchlight/search.rb
CHANGED
@@ -35,10 +35,8 @@ module Searchlight
|
|
35
35
|
raise MissingSearchTarget, "No search target provided via `search_on` and Searchlight can't guess one."
|
36
36
|
end
|
37
37
|
rescue NameError => e
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
raise e
|
38
|
+
raise e unless /uninitialized constant/.match(e.message)
|
39
|
+
raise MissingSearchTarget, "No search target provided via `search_on` and Searchlight's guess was wrong. Error: #{e.message}"
|
42
40
|
end
|
43
41
|
|
44
42
|
def self.search_target=(value)
|
data/lib/searchlight/version.rb
CHANGED
@@ -7,67 +7,114 @@ describe Searchlight::Search do
|
|
7
7
|
let(:provided_options) { Hash.new }
|
8
8
|
let(:search) { search_class.new(provided_options) }
|
9
9
|
|
10
|
-
describe "
|
10
|
+
describe "options" do
|
11
11
|
|
12
|
-
|
12
|
+
context "when given valid options" do
|
13
13
|
|
14
|
-
|
15
|
-
let(:provided_options) { {beak_color: 'mauve'} }
|
14
|
+
context "when the search class has no defaults" do
|
16
15
|
|
17
|
-
|
18
|
-
search_class.searches :beak_color
|
19
|
-
expect(search.beak_color).to eq('mauve')
|
20
|
-
end
|
16
|
+
describe "screening options" do
|
21
17
|
|
22
|
-
|
18
|
+
let(:allowed_options) { [:name, :description, :categories, :nicknames] }
|
23
19
|
|
24
|
-
|
20
|
+
context "when all options are usable" do
|
25
21
|
|
26
|
-
|
22
|
+
let(:provided_options) { {name: 'Roy', description: 'Ornry', categories: %w[mammal moonshiner], nicknames: %w[Slim Bubba]} }
|
27
23
|
|
28
|
-
|
24
|
+
it "adds them to the options accessor" do
|
25
|
+
expect(search.options).to eq(provided_options)
|
26
|
+
end
|
29
27
|
|
30
|
-
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
expect(search.options).to eq(provided_options)
|
34
|
-
end
|
30
|
+
context "when some provided options are empty" do
|
35
31
|
|
36
|
-
|
32
|
+
let(:provided_options) { {name: 'Roy', description: '', categories: ['', ''], nicknames: []} }
|
37
33
|
|
38
|
-
|
34
|
+
it "does not add them to the options accessor" do
|
35
|
+
expect(search.options).to eq(name: 'Roy')
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
expect(search.options).to eq(name: 'Roy')
|
44
|
-
end
|
40
|
+
context "when an empty options hash is given" do
|
45
41
|
|
46
|
-
|
42
|
+
let(:provided_options) { {} }
|
43
|
+
|
44
|
+
it "has empty options" do
|
45
|
+
expect(search.options).to eq({})
|
46
|
+
end
|
47
47
|
|
48
|
-
|
48
|
+
end
|
49
49
|
|
50
|
-
|
50
|
+
context "when the options are explicitly nil" do
|
51
|
+
|
52
|
+
let(:provided_options) { nil }
|
53
|
+
|
54
|
+
it "has empty options" do
|
55
|
+
expect(search.options).to eq({})
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
51
59
|
|
52
|
-
it "has empty options" do
|
53
|
-
expect(search.options).to eq({})
|
54
60
|
end
|
55
61
|
|
56
62
|
end
|
57
63
|
|
58
|
-
context "when the
|
64
|
+
context "when the search class has defaults" do
|
65
|
+
|
66
|
+
context "when they're set during initialization" do
|
67
|
+
|
68
|
+
let(:allowed_options) { [:name, :age] }
|
69
|
+
let(:search_class) {
|
70
|
+
Named::Class.new('ExampleSearch', described_class) do
|
71
|
+
|
72
|
+
def initialize(options)
|
73
|
+
super
|
74
|
+
self.name ||= 'Dennis'
|
75
|
+
self.age ||= 37
|
76
|
+
end
|
77
|
+
|
78
|
+
end.tap { |klass| klass.searches *allowed_options }
|
79
|
+
}
|
59
80
|
|
60
|
-
|
81
|
+
context "and there were no values given" do
|
82
|
+
|
83
|
+
let(:provided_options) { Hash.new }
|
84
|
+
|
85
|
+
it "uses the defaults for its accessors" do
|
86
|
+
expect(search.name).to eq('Dennis')
|
87
|
+
expect(search.age).to eq(37)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "uses the defaults for its options hash" do
|
91
|
+
expect(search.options).to eq({name: 'Dennis', age: 37})
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "and values are given" do
|
97
|
+
|
98
|
+
let(:provided_options) { {name: 'Treebeard', age: 'A few thousand'} }
|
99
|
+
|
100
|
+
it "uses the provided values" do
|
101
|
+
expect(search.name).to eq('Treebeard')
|
102
|
+
expect(search.age).to eq('A few thousand')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "uses the provided values for its options hash" do
|
106
|
+
expect(search.options).to eq({name: 'Treebeard', age: 'A few thousand'})
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
61
110
|
|
62
|
-
it "has empty options" do
|
63
|
-
expect(search.options).to eq({})
|
64
111
|
end
|
65
112
|
|
66
113
|
end
|
67
114
|
|
68
115
|
end
|
69
116
|
|
70
|
-
|
117
|
+
context "when given invalid options" do
|
71
118
|
|
72
119
|
let(:provided_options) { {genus: 'Mellivora'} }
|
73
120
|
|
@@ -75,6 +122,11 @@ describe Searchlight::Search do
|
|
75
122
|
expect { search }.to raise_error( Searchlight::Search::UndefinedOption, /ExampleSearch.*genus/)
|
76
123
|
end
|
77
124
|
|
125
|
+
it "gives the error a readable string representation" do
|
126
|
+
error = Searchlight::Search::UndefinedOption.new(:badger_height, Array)
|
127
|
+
expect(error.to_s).to eq(error.message)
|
128
|
+
end
|
129
|
+
|
78
130
|
context "if the provided option starts with 'search_'" do
|
79
131
|
|
80
132
|
let(:allowed_options) { [:genus] }
|
@@ -173,9 +225,9 @@ describe Searchlight::Search do
|
|
173
225
|
|
174
226
|
end
|
175
227
|
|
176
|
-
describe "
|
228
|
+
describe "individual option accessors" do
|
177
229
|
|
178
|
-
describe "accessors" do
|
230
|
+
describe "the accessors module" do
|
179
231
|
|
180
232
|
before :each do
|
181
233
|
search_class.searches :foo
|
@@ -188,49 +240,54 @@ describe Searchlight::Search do
|
|
188
240
|
expect(accessors_modules.length).to eq(1)
|
189
241
|
expect(accessors_modules.first).to be_a(Named::Module)
|
190
242
|
end
|
243
|
+
end
|
191
244
|
|
192
|
-
|
193
|
-
expect(search).to respond_to(:foo)
|
194
|
-
end
|
245
|
+
describe "value accessors" do
|
195
246
|
|
196
|
-
|
197
|
-
|
247
|
+
let(:allowed_options) { [:beak_color] }
|
248
|
+
let(:provided_options) { {beak_color: 'mauve'} }
|
249
|
+
|
250
|
+
it "provides an getter for the value" do
|
251
|
+
search_class.searches :beak_color
|
252
|
+
expect(search.beak_color).to eq('mauve')
|
198
253
|
end
|
199
254
|
|
200
|
-
it "
|
201
|
-
|
255
|
+
it "provides an setter for the value" do
|
256
|
+
search_class.searches :beak_color
|
257
|
+
search.beak_color = 'turquoise'
|
258
|
+
expect(search.beak_color).to eq('turquoise')
|
202
259
|
end
|
203
260
|
|
204
261
|
end
|
205
262
|
|
206
|
-
describe "
|
263
|
+
describe "boolean accessors" do
|
207
264
|
|
208
|
-
let(:provided_options) { {
|
265
|
+
let(:provided_options) { {has_beak: has_beak} }
|
209
266
|
|
210
267
|
before :each do
|
211
|
-
search_class.searches :
|
268
|
+
search_class.searches :has_beak
|
212
269
|
end
|
213
270
|
|
214
271
|
{
|
215
|
-
|
216
|
-
|
217
|
-
''
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
'
|
223
|
-
|
224
|
-
|
225
|
-
'
|
272
|
+
'yeppers' => true,
|
273
|
+
1 => true,
|
274
|
+
'1' => true,
|
275
|
+
15 => true,
|
276
|
+
'true' => true,
|
277
|
+
0 => false,
|
278
|
+
'0' => false,
|
279
|
+
'' => false,
|
280
|
+
' ' => false,
|
281
|
+
nil => false,
|
282
|
+
'false' => false
|
226
283
|
}.each do |input, output|
|
227
284
|
|
228
285
|
describe input.inspect do
|
229
286
|
|
230
|
-
let(:
|
287
|
+
let(:has_beak) { input }
|
231
288
|
|
232
289
|
it "becomes boolean #{output}" do
|
233
|
-
expect(search.
|
290
|
+
expect(search.has_beak?).to eq(output)
|
234
291
|
end
|
235
292
|
|
236
293
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Long
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: named
|
@@ -57,28 +57,28 @@ dependencies:
|
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rails
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '3'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - '>='
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '3'
|
84
84
|
- !ruby/object:Gem::Dependency
|
@@ -154,12 +154,12 @@ require_paths:
|
|
154
154
|
- lib
|
155
155
|
required_ruby_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
|
-
- -
|
162
|
+
- - '>='
|
163
163
|
- !ruby/object:Gem::Version
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|