searchlight 3.1.1 → 4.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.
data/spec/spec_helper.rb CHANGED
@@ -2,12 +2,9 @@ require 'capybara/rspec'
2
2
  require 'searchlight'
3
3
  $LOAD_PATH << '.'
4
4
  require 'support/mock_model'
5
- require 'support/account_search'
6
- require 'support/spiffy_account_search'
7
- require 'support/proc_search'
5
+ require 'support/book_search'
8
6
 
9
7
  RSpec.configure do |config|
10
- config.treat_symbols_as_metadata_keys_with_true_values = true
11
8
  config.run_all_when_everything_filtered = true
12
9
  config.filter_run :focus
13
10
 
@@ -0,0 +1,46 @@
1
+ # Mostly taken from example app
2
+ class BookSearch < Searchlight::Search
3
+ Book = Class.new(MockModel)
4
+ Author = Class.new(MockModel)
5
+
6
+ def base_query
7
+ Book.all.order("title ASC")
8
+ end
9
+
10
+ def options
11
+ super.tap { |opts|
12
+ opts[:in_print] ||= "either"
13
+ }
14
+ end
15
+
16
+ def search_title_like
17
+ query.merge(Book.title_like(options[:title_like]))
18
+ end
19
+
20
+ def search_category_in
21
+ query.where(category_id: options.fetch(:category_in).reject {|v| blank?(v) })
22
+ end
23
+
24
+ def search_author_name_like
25
+ query.joins(:author).merge(Author.name_like(options[:author_name_like]))
26
+ end
27
+
28
+ def search_author_also_wrote_in_category_id
29
+ query_string = <<-YE_OLDE_QUERY_LANGUAGE.strip_heredoc
30
+ INNER JOIN authors AS category_authors ON books.author_id = category_authors.id
31
+ INNER JOIN books AS other_books ON other_books.author_id = category_authors.id
32
+ INNER JOIN categories AS other_categories ON other_books.category_id = other_categories.id
33
+ YE_OLDE_QUERY_LANGUAGE
34
+ query.joins(query_string).where("other_categories.id = ?", options[:author_also_wrote_in_category_id])
35
+ end
36
+
37
+ def search_board_book
38
+ query.where(board_book: checked?(options[:board_book]))
39
+ end
40
+
41
+ def search_in_print
42
+ return query if options[:in_print].to_s == "either"
43
+ query.where(in_print: checked?(options[:in_print]))
44
+ end
45
+
46
+ 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: 3.1.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Long
@@ -9,36 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-21 00:00:00.000000000 Z
12
+ date: 2015-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: named
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1.0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1.0'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: rspec
30
16
  requirement: !ruby/object:Gem::Requirement
31
17
  requirements:
32
18
  - - "~>"
33
19
  - !ruby/object:Gem::Version
34
- version: '2.14'
20
+ version: '3.2'
35
21
  type: :development
36
22
  prerelease: false
37
23
  version_requirements: !ruby/object:Gem::Requirement
38
24
  requirements:
39
25
  - - "~>"
40
26
  - !ruby/object:Gem::Version
41
- version: '2.14'
27
+ version: '3.2'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: bundler
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +59,14 @@ dependencies:
73
59
  requirements:
74
60
  - - "~>"
75
61
  - !ruby/object:Gem::Version
76
- version: '2.0'
62
+ version: '2.4'
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: '2.0'
69
+ version: '2.4'
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: actionview
86
72
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +109,7 @@ files:
123
109
  - ".rspec"
124
110
  - ".travis.yml"
125
111
  - CHANGELOG.md
112
+ - CODE_OF_CONDUCT.md
126
113
  - Gemfile
127
114
  - LICENSE.txt
128
115
  - README.md
@@ -132,18 +119,17 @@ files:
132
119
  - gemfiles/Gemfile.rails-4.0.x
133
120
  - lib/searchlight.rb
134
121
  - lib/searchlight/adapters/action_view.rb
135
- - lib/searchlight/dsl.rb
122
+ - lib/searchlight/options.rb
136
123
  - lib/searchlight/search.rb
137
124
  - lib/searchlight/version.rb
138
125
  - searchlight.gemspec
139
126
  - spec/searchlight/adapters/action_view_spec.rb
127
+ - spec/searchlight/options_spec.rb
140
128
  - spec/searchlight/search_spec.rb
141
129
  - spec/searchlight_spec.rb
142
130
  - spec/spec_helper.rb
143
- - spec/support/account_search.rb
131
+ - spec/support/book_search.rb
144
132
  - spec/support/mock_model.rb
145
- - spec/support/proc_search.rb
146
- - spec/support/spiffy_account_search.rb
147
133
  homepage: https://github.com/nathanl/searchlight
148
134
  licenses:
149
135
  - MIT
@@ -164,16 +150,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
150
  version: '0'
165
151
  requirements: []
166
152
  rubyforge_project:
167
- rubygems_version: 2.2.2
153
+ rubygems_version: 2.4.5
168
154
  signing_key:
169
155
  specification_version: 4
170
156
  summary: Searchlight is a low-magic way to build database searches using an ORM.
171
157
  test_files:
172
158
  - spec/searchlight/adapters/action_view_spec.rb
159
+ - spec/searchlight/options_spec.rb
173
160
  - spec/searchlight/search_spec.rb
174
161
  - spec/searchlight_spec.rb
175
162
  - spec/spec_helper.rb
176
- - spec/support/account_search.rb
163
+ - spec/support/book_search.rb
177
164
  - spec/support/mock_model.rb
178
- - spec/support/proc_search.rb
179
- - spec/support/spiffy_account_search.rb
@@ -1,33 +0,0 @@
1
- module Searchlight
2
- module DSL
3
-
4
- def search_on(target)
5
- @search_target = target
6
- end
7
-
8
- def searches(*attribute_names)
9
-
10
- # Ensure this class only adds one accessors module to the ancestors chain
11
- if @accessors_module.nil?
12
- @accessors_module = Named::Module.new("SearchlightAccessors(#{self})") do
13
- private
14
- # Treat 0 (eg, from checkboxes) as false
15
- def truthy?(value)
16
- !(['0', 'false', ''].include?(value.to_s.strip))
17
- end
18
- end
19
- include @accessors_module
20
- end
21
-
22
- eval_string = "attr_accessor *#{attribute_names}\n"
23
- eval_string << attribute_names.map { |attribute_name|
24
- <<-LEPRECHAUN_JUICE
25
- def #{attribute_name}?
26
- truthy?(public_send("#{attribute_name}"))
27
- end
28
- LEPRECHAUN_JUICE
29
- }.join
30
- @accessors_module.module_eval(eval_string, __FILE__, __LINE__)
31
- end
32
- end
33
- end
@@ -1,16 +0,0 @@
1
- class AccountSearch < Searchlight::Search
2
-
3
- search_on MockModel
4
-
5
- searches :paid_amount, :business_name, :balance, :active
6
- attr_accessor :other_attribute
7
-
8
- def search_paid_amount
9
- search.where('amount > ?', paid_amount)
10
- end
11
-
12
- def search_business_name
13
- search.where(business_name: business_name)
14
- end
15
-
16
- end
@@ -1,17 +0,0 @@
1
- class ProcSearch < Searchlight::Search
2
-
3
- searches :first_name
4
-
5
- search_on proc { MockModel.some_scope }
6
-
7
- def search_first_name
8
- search.where(first_name: first_name)
9
- end
10
-
11
- end
12
-
13
- class ChildProcSearch < ProcSearch
14
-
15
- search_on proc { superclass.search_target.call.other_scope }
16
-
17
- end
@@ -1,2 +0,0 @@
1
- class SpiffyAccountSearch < AccountSearch
2
- end