searchgasm 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +34 -21
  3. data/{README.mdown → README.rdoc} +96 -63
  4. data/Rakefile +1 -1
  5. data/examples/README.rdoc +4 -0
  6. data/lib/searchgasm/active_record/associations.rb +40 -42
  7. data/lib/searchgasm/active_record/base.rb +75 -61
  8. data/lib/searchgasm/condition/base.rb +127 -0
  9. data/lib/searchgasm/condition/begins_with.rb +20 -0
  10. data/lib/searchgasm/condition/child_of.rb +11 -0
  11. data/lib/searchgasm/condition/contains.rb +20 -0
  12. data/lib/searchgasm/condition/descendant_of.rb +24 -0
  13. data/lib/searchgasm/condition/does_not_equal.rb +28 -0
  14. data/lib/searchgasm/condition/ends_with.rb +20 -0
  15. data/lib/searchgasm/condition/equals.rb +20 -0
  16. data/lib/searchgasm/condition/greater_than.rb +25 -0
  17. data/lib/searchgasm/condition/greater_than_or_equal_to.rb +20 -0
  18. data/lib/searchgasm/condition/inclusive_descendant_of.rb +13 -0
  19. data/lib/searchgasm/condition/keywords.rb +33 -0
  20. data/lib/searchgasm/condition/less_than.rb +25 -0
  21. data/lib/searchgasm/condition/less_than_or_equal_to.rb +20 -0
  22. data/lib/searchgasm/condition/sibling_of.rb +16 -0
  23. data/lib/searchgasm/condition/tree.rb +16 -0
  24. data/lib/searchgasm/conditions/base.rb +221 -0
  25. data/lib/searchgasm/conditions/protection.rb +30 -0
  26. data/lib/searchgasm/config.rb +137 -0
  27. data/lib/searchgasm/helpers/form_helper.rb +159 -0
  28. data/lib/searchgasm/helpers/search_helper.rb +178 -0
  29. data/lib/searchgasm/helpers/utilities_helper.rb +125 -0
  30. data/lib/searchgasm/search/base.rb +73 -179
  31. data/lib/searchgasm/search/conditions.rb +42 -166
  32. data/lib/searchgasm/search/ordering.rb +149 -0
  33. data/lib/searchgasm/search/pagination.rb +69 -0
  34. data/lib/searchgasm/search/protection.rb +61 -0
  35. data/lib/searchgasm/utilities.rb +30 -0
  36. data/lib/searchgasm/version.rb +44 -47
  37. data/lib/searchgasm.rb +57 -21
  38. data/searchgasm.gemspec +71 -46
  39. data/test/test_active_record_associations.rb +1 -1
  40. data/test/test_active_record_base.rb +4 -4
  41. data/test/test_condition.rb +143 -0
  42. data/test/{test_searchgasm_conditions.rb → test_conditions_base.rb} +43 -33
  43. data/test/test_search_base.rb +189 -0
  44. data/test/test_search_ordering.rb +91 -0
  45. data/test/test_search_pagination.rb +56 -0
  46. data/test/test_search_protection.rb +35 -0
  47. metadata +70 -45
  48. data/lib/searchgasm/search/condition.rb +0 -105
  49. data/lib/searchgasm/search/condition_types/begins_with_condition.rb +0 -26
  50. data/lib/searchgasm/search/condition_types/child_of_condition.rb +0 -17
  51. data/lib/searchgasm/search/condition_types/contains_condition.rb +0 -26
  52. data/lib/searchgasm/search/condition_types/descendant_of_condition.rb +0 -30
  53. data/lib/searchgasm/search/condition_types/does_not_equal_condition.rb +0 -34
  54. data/lib/searchgasm/search/condition_types/ends_with_condition.rb +0 -26
  55. data/lib/searchgasm/search/condition_types/equals_condition.rb +0 -26
  56. data/lib/searchgasm/search/condition_types/greater_than_condition.rb +0 -31
  57. data/lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb +0 -26
  58. data/lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb +0 -19
  59. data/lib/searchgasm/search/condition_types/keywords_condition.rb +0 -39
  60. data/lib/searchgasm/search/condition_types/less_than_condition.rb +0 -31
  61. data/lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb +0 -26
  62. data/lib/searchgasm/search/condition_types/sibling_of_condition.rb +0 -22
  63. data/lib/searchgasm/search/condition_types/tree_condition.rb +0 -20
  64. data/lib/searchgasm/search/utilities.rb +0 -34
  65. data/test/test_searchgasm_base.rb +0 -185
  66. data/test/test_searchgasm_condition_types.rb +0 -143
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.9.7. Complete class restructure, much more organized, added in documentation, added in helpers for using searchgasm in a rails app, updated readme with link to documentation as well as a live example, some bug fixes, more tests
2
+
1
3
  v0.9.6. Fix bug when instantiating with nil options
2
4
 
3
5
  v0.9.5. Enhanced searching with conditions only. Updated read me to include example on adding your own conditions.
data/Manifest CHANGED
@@ -1,32 +1,42 @@
1
1
  CHANGELOG
2
+ examples/README.rdoc
2
3
  init.rb
3
4
  lib/searchgasm/active_record/associations.rb
4
5
  lib/searchgasm/active_record/base.rb
6
+ lib/searchgasm/condition/base.rb
7
+ lib/searchgasm/condition/begins_with.rb
8
+ lib/searchgasm/condition/child_of.rb
9
+ lib/searchgasm/condition/contains.rb
10
+ lib/searchgasm/condition/descendant_of.rb
11
+ lib/searchgasm/condition/does_not_equal.rb
12
+ lib/searchgasm/condition/ends_with.rb
13
+ lib/searchgasm/condition/equals.rb
14
+ lib/searchgasm/condition/greater_than.rb
15
+ lib/searchgasm/condition/greater_than_or_equal_to.rb
16
+ lib/searchgasm/condition/inclusive_descendant_of.rb
17
+ lib/searchgasm/condition/keywords.rb
18
+ lib/searchgasm/condition/less_than.rb
19
+ lib/searchgasm/condition/less_than_or_equal_to.rb
20
+ lib/searchgasm/condition/sibling_of.rb
21
+ lib/searchgasm/condition/tree.rb
22
+ lib/searchgasm/conditions/base.rb
23
+ lib/searchgasm/conditions/protection.rb
24
+ lib/searchgasm/config.rb
25
+ lib/searchgasm/helpers/form_helper.rb
26
+ lib/searchgasm/helpers/search_helper.rb
27
+ lib/searchgasm/helpers/utilities_helper.rb
5
28
  lib/searchgasm/search/base.rb
6
- lib/searchgasm/search/condition.rb
7
- lib/searchgasm/search/condition_types/begins_with_condition.rb
8
- lib/searchgasm/search/condition_types/child_of_condition.rb
9
- lib/searchgasm/search/condition_types/contains_condition.rb
10
- lib/searchgasm/search/condition_types/descendant_of_condition.rb
11
- lib/searchgasm/search/condition_types/does_not_equal_condition.rb
12
- lib/searchgasm/search/condition_types/ends_with_condition.rb
13
- lib/searchgasm/search/condition_types/equals_condition.rb
14
- lib/searchgasm/search/condition_types/greater_than_condition.rb
15
- lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb
16
- lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb
17
- lib/searchgasm/search/condition_types/keywords_condition.rb
18
- lib/searchgasm/search/condition_types/less_than_condition.rb
19
- lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb
20
- lib/searchgasm/search/condition_types/sibling_of_condition.rb
21
- lib/searchgasm/search/condition_types/tree_condition.rb
22
29
  lib/searchgasm/search/conditions.rb
23
- lib/searchgasm/search/utilities.rb
30
+ lib/searchgasm/search/ordering.rb
31
+ lib/searchgasm/search/pagination.rb
32
+ lib/searchgasm/search/protection.rb
33
+ lib/searchgasm/utilities.rb
24
34
  lib/searchgasm/version.rb
25
35
  lib/searchgasm.rb
26
36
  Manifest
27
37
  MIT-LICENSE
28
38
  Rakefile
29
- README.mdown
39
+ README.rdoc
30
40
  test/fixtures/accounts.yml
31
41
  test/fixtures/orders.yml
32
42
  test/fixtures/users.yml
@@ -34,7 +44,10 @@ test/libs/acts_as_tree.rb
34
44
  test/libs/rexml_fix.rb
35
45
  test/test_active_record_associations.rb
36
46
  test/test_active_record_base.rb
47
+ test/test_condition.rb
48
+ test/test_conditions_base.rb
37
49
  test/test_helper.rb
38
- test/test_searchgasm_base.rb
39
- test/test_searchgasm_condition_types.rb
40
- test/test_searchgasm_conditions.rb
50
+ test/test_search_base.rb
51
+ test/test_search_ordering.rb
52
+ test/test_search_pagination.rb
53
+ test/test_search_protection.rb
@@ -1,36 +1,19 @@
1
- # Searchgasm
1
+ = Searchgasm
2
2
 
3
3
  Searchgasm is orgasmic. Maybe not orgasmic, but you will get aroused. So go grab a towel and let's dive in.
4
4
 
5
- Searchgasm was a super secret tool of mine until I decided to share with the world. It has saved me tons of time, allowed me to write less code, made searching painless, and kept my controllers DRY and simple.
5
+ <b>Searchgasm's inspiration comes right from ActiveRecord. ActiveRecord lets you create objects that represent a record in the database, so why can't you create objects that represent searching the database? Now you can!</b>
6
6
 
7
- It originated to satisfy a VERY simple need: so that I could use my form builder when making search forms. Sounds simple right? The goal was to use an object, that represents a search, just like an ActiveRecord object in form\_for and fields\_for.
7
+ == Under the hood
8
8
 
9
- I'm a big fan of understanding what I'm using, so here's a quick explanation: The design behind this plugin is pretty simple. The search object "santiizes" down into the options passed into ActiveRecord::Base.find(). It basically serves as a transparent filter between you and ActiveRecord::Base.find(). This filter provides "enhancements" that get translated into options that ActiveRecord::Base.find() can understand. It doesn't dig into the ActiveRecord internals, it only uses what is publicly available. It jumps in and helps out only when needed, otherwise it sits back and lets ActiveRecord do all of the work. Between that and the extensive tests this is a solid plugin.
9
+ I'm a big fan of understanding what I'm using, so here's a quick explanation: The design behind this plugin is pretty simple. The search object "sanitizes" down into the options passed into ActiveRecord::Base.find(). It serves as a transparent filter between you and ActiveRecord::Base.find(). This filter provides "enhancements" that get translated into options that ActiveRecord::Base.find() can understand. It doesn't dig into the ActiveRecord internals, it only uses what is publicly available. It jumps in and helps out <em>only</em> when needed, otherwise it sits back and lets ActiveRecord do all of the work. Between that and the extensive tests, this is a solid and fast plugin.
10
10
 
11
- Here's where you get aroused...
11
+ == Quicklinks
12
12
 
13
- ## Why I love Searchgasm!
13
+ * <b>Documentation:</b> http://searchgasm.rubyforge.org
14
+ * <b>Live rails example:</b> http://searchgasm_example.binarylogic.com
14
15
 
15
- # app/controllers/users_controller.rb
16
- def index
17
- @search = User.new_search(:conditions => params[:conditions])
18
- @users, @users_count = @search.all, @search.count
19
- end
20
-
21
- Now your view, isn't it nice to use form builder again?
22
-
23
- # app/views/users/index.html.erb
24
- <%= form_for :conditions, @search.conditions, :url => users_path do |f| %>
25
- <%= f.text_field :first_name_contains %>
26
- <%= f.calendar_date_select :created_after %> # nice rails plugin for replacing date_select
27
- <% f.fields_for :orders, f.object.orders do |orders_f| %>
28
- <%= f.select :total_gt, (1..100) %>
29
- <% end %>
30
- <%= f.submit %>
31
- <% end %>
32
-
33
- ## Install and use
16
+ == Install and use
34
17
 
35
18
  sudo gem install searchgasm
36
19
 
@@ -48,11 +31,52 @@ Or as a plugin
48
31
 
49
32
  script/plugin install git://github.com/binarylogic/searchgasm.git
50
33
 
51
- Now go into your console and try out any of these example with your own models.
34
+ Now try out some of the examples below:
52
35
 
53
- **For all examples, let's assume the following relationships: User => Orders => Line Items**
36
+ <b>For all examples, let's assume the following relationships: User => Orders => Line Items</b>
54
37
 
55
- ## Simple Searching Example
38
+ == The beauty of searchgasm
39
+
40
+ Using Searchgasm in rails is the best part, because rails has all kinds of nifty methods to make dealing with ActiveRecord objects quick and easy, especially with forms. So let's take advantage of them! That's the idea behind this plugin. Searchgasm is searching, ordering, and pagination all rolled into one simple plugin. Take all of that pagination and searching cruft out of your models and let Searchgasm handle it. Check it out:
41
+
42
+ # app/controllers/users_controller.rb
43
+ def index
44
+ @search = User.new_search(params[:search])
45
+ @users, @users_count = @search.all, @search.count
46
+ end
47
+
48
+ Now your view. Notice you can use your search object <b>just like</b> an ActiveRecord object.
49
+
50
+ # app/views/users/index.html.haml
51
+ - form_for @search do |f|
52
+ - f.fields_for @search.conditions do |users|
53
+ = users.text_field :first_name_contains
54
+ = users.calendar_date_select :created_after # nice rails plugin for replacing date_select
55
+ - users.fields_for users.object.orders do |orders|
56
+ = orders.select :total_gt, (1..100)
57
+ = f.submit "Search"
58
+
59
+ %table
60
+ %tr
61
+ %th= order_by :first_name
62
+ %th= order_by :last_name
63
+ %th= order_by :email
64
+ - @users.each do |user|
65
+ %tr
66
+ %td= user.first_name
67
+ %td= user.last_name
68
+ %td= user.email
69
+
70
+ Per page:
71
+ = per_page
72
+ Page:
73
+ = page
74
+
75
+ Nice and simple. 2 lines in your controller, no "cruft" in your models, pagination as simple as calling the "page" and "per_page" helpers, ordering as simple as calling "order_by", and all searching conditions in 1 spot: your form. For documentation on helpers see Searchgasm::Helpers::FormHelper and Searchgasm::Helpers::SearchHelper.
76
+
77
+ <b>See this example live: http://searchgasm_example.binarylogic.com</b>
78
+
79
+ == Simple Searching Example
56
80
 
57
81
  User.all(
58
82
  :conditions => {
@@ -60,12 +84,12 @@ Now go into your console and try out any of these example with your own models.
60
84
  :email_ends_with => "binarylogic.com" # email like '%binarylogic.com'
61
85
  },
62
86
  :per_page => 20 # limit 20
63
- :page => 3 # offset 60
87
+ :page => 3 # offset 40, which starts us on page 3
64
88
  )
65
89
 
66
- Instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc
90
+ Instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc, just like ActiveRecord
67
91
 
68
- ## Detailed Example w/ object based searching (great for form\_for or fields\_for)
92
+ == Exhaustive Example w/ Object Based Searching (great for form_for or fields_for)
69
93
 
70
94
  # Instantiate
71
95
  @search = User.new_search(
@@ -80,12 +104,16 @@ Instead of using the "all" method you could use any search method: first, find(:
80
104
  :order_as => "DESC"
81
105
  )
82
106
 
83
- # Set conditions on relationships
107
+ # Set local conditions
84
108
  @search.conditions.email_ends_with = "binarylogic.com"
85
- @search.conditions.oders.line_items.created_after = Time.now
109
+
110
+ # Set conditions on relationships
111
+ @search.conditions.oders.line_items.created_after = Time.now # can traverse through all relationships
86
112
 
87
113
  # Set options
88
- @search.per_page = 50 # overrides the 20 set above
114
+ @search.per_page = 50 # overrides the 20 set above
115
+ @search.order_by = [:first_name, {:user_group => :name}] # order by first name and then by the user group's name it belongs to
116
+ @search.order_as = "ASC"
89
117
 
90
118
  # Set ANY of the ActiveRecord options
91
119
  @search.group = "last_name"
@@ -94,12 +122,11 @@ Instead of using the "all" method you could use any search method: first, find(:
94
122
 
95
123
  # Return results just like ActiveRecord
96
124
  @search.all
97
- @search.search # alias for all
98
125
  @search.first
99
126
 
100
127
  Take the @search object and pass it right into form\_for or fields\_for (see above).
101
128
 
102
- ## Calculations
129
+ == Calculations
103
130
 
104
131
  Using the object from above:
105
132
 
@@ -108,7 +135,8 @@ Using the object from above:
108
135
  @search.maximum('id')
109
136
  @search.minimum('id')
110
137
  @search.sum('id')
111
- @search.calculate(:sum, 'id') # any of the above calculations
138
+ @search.calculate(:sum, 'id')
139
+ # ...any of the above calculations, see ActiveRecord documentation on calculations
112
140
 
113
141
  Or do it from your model:
114
142
 
@@ -116,7 +144,7 @@ Or do it from your model:
116
144
  User.sum('id', :conditions => {:first_name_contains => "Ben"})
117
145
  # ... all other calcualtions, etc.
118
146
 
119
- ## Different ways to search, take your pick
147
+ == Different ways to search, take your pick
120
148
 
121
149
  Any of the options used in the above example can be used in these, but for the sake of brevity I am only using a few:
122
150
 
@@ -133,34 +161,33 @@ Any of the options used in the above example can be used in these, but for the s
133
161
  search.per_page = 20
134
162
  search.all
135
163
 
136
- If you want to be hardcore:
164
+ If you want to use Searchgasm directly:
137
165
 
138
- search = Searchgasm::Search.new(User, :conditions => {:age_gt => 18})
166
+ search = Searchgasm::Search::Base.new(User, :conditions => {:age_gt => 18})
139
167
  search.conditions.first_name_contains = "Ben"
140
168
  search.per_page = 20
141
169
  search.all
142
170
 
143
- ## Search with conditions only
171
+ == Search with conditions only
144
172
 
145
173
  conditions = User.new_conditions(:age_gt => 18)
146
174
  conditions.first_name_contains = "Ben"
147
- conditions.search
148
175
  conditions.all
149
176
  # ... all operations above are available
150
177
 
151
178
  Pass a conditions object right into ActiveRecord:
152
179
 
153
- User.all(:conditions => conditions) # same as conditions.search
180
+ User.all(:conditions => conditions)
154
181
 
155
- Again, if you want to be hardcore:
182
+ Again, if you want to use Searchgasm directly:
156
183
 
157
- conditions = Searchgasm::Conditions.new(User, :age_gt => 18)
184
+ conditions = Searchgasm::Conditions::Base.new(User, :age_gt => 18)
158
185
  conditions.first_name_contains = "Ben"
159
- conditions.search
186
+ conditions.all
160
187
 
161
188
  Now pass the conditions object right into form\_for or fields\_for (see above for example).
162
189
 
163
- ## Scoped searching
190
+ == Scoped searching
164
191
 
165
192
  @current_user.orders.find(:all, :conditions => {:total_lte => 500})
166
193
  @current_user.orders.count(:conditions => {:total_lte => 500})
@@ -168,7 +195,7 @@ Now pass the conditions object right into form\_for or fields\_for (see above fo
168
195
 
169
196
  search = @current_user.orders.build_search('total', :conditions => {:total_lte => 500})
170
197
 
171
- ## Searching trees
198
+ == Searching trees
172
199
 
173
200
  For tree data structures you get a few nifty methods. Let's assume Users is a tree data structure.
174
201
 
@@ -189,25 +216,25 @@ For tree data structures you get a few nifty methods. Let's assume Users is a tr
189
216
  User.all(:conditions => {:inclusive_descendant_of => User.roots.first.id})
190
217
 
191
218
 
192
- ## Available anywhere (relationships & named scopes)
219
+ == Available anywhere (relationships & scopes)
193
220
 
194
- Not only can you use searchgasm when searching, but you can use it when setting up relationships or named scopes:
221
+ Not only can you use searchgasm when searching, but you can use it when setting up relationships or scopes. Anywhere you specify conditions in ActiveRecord.
195
222
 
196
223
  class User < ActiveRecord::Base
197
224
  has_many :expensive_pending_orders, :conditions => {:total_greater_than => 1_000_000, :state => :pending}, :per_page => 20
198
225
  named_scope :sexy, :conditions => {:first_name => "Ben", email_ends_with => "binarylogic.com"}, :per_page => 20
199
226
  end
200
227
 
201
- ## Always use protection...against SQL injections
228
+ == Always use protection...against SQL injections
202
229
 
203
- If there is one thing we all know, it's to always use protection. That's why searchgasm protects you by default. The new\_search and new\_conditions methods are protected by default. This means that various checks are done to ensure it is not possible to perform any type of SQL injection. But this also limits how you can search, meaning you can't write raw SQL. If you want to be daring and search without protection prepare to accept the consequences. All that you have to do is add ! to the end of the methods: new\_search! and new\_conditions!.
230
+ If there is one thing we all know, it's to always use protection against SQL injections. That's why searchgasm protects you by default. The new\_search and new\_conditions methods are protected by default. This means that various checks are done to ensure it is not possible to perform any type of SQL injection. But this also limits how you can search, meaning you can't write raw SQL. If you want to be daring and search without protection, all that you have to do is add ! to the end of the methods: new\_search! and new\_conditions!.
204
231
 
205
- ### Protected from SQL injections
232
+ === Protected from SQL injections
206
233
 
207
234
  search = Account.new_search(params[:search])
208
235
  conditions = Account.new_conditions(params[:conditions])
209
236
 
210
- ### *NOT* protected from SQL injections
237
+ === *NOT* protected from SQL injections
211
238
 
212
239
  accounts = Account.find(params[:search])
213
240
  accounts = Account.all(params[:search])
@@ -217,7 +244,7 @@ If there is one thing we all know, it's to always use protection. That's why sea
217
244
 
218
245
  Lesson learned: use new\_search and new\_conditions when passing in params as *ANY* of the options.
219
246
 
220
- ## Available Conditions
247
+ == Available Conditions
221
248
 
222
249
  Depending on the type, each column comes preloaded with a bunch of nifty conditions:
223
250
 
@@ -246,11 +273,13 @@ Some of these conditions come with aliases, so you have your choice how to call
246
273
  :less_than => :lt, :before
247
274
  :less_than_or_equal_to => :at_most, :lte
248
275
 
249
- ### Enhanced searching and blacklisted words
276
+ For more information on each condition see Searchgasm::Condition. Each condition has it's own class and the source is pretty simple and self explanatory.
277
+
278
+ === Enhanced searching and blacklisted words
250
279
 
251
280
  You will notice above there is "contains" and "keywords". The difference is that "keywords" is an enhanced search. It acts like a real keyword search. It finds those keywords, in any order, and blacklists meaningless words such as "and", "the", etc. "contains" finds the EXACT string in the column you are searching, spaces and all.
252
281
 
253
- ### Roll your own conditions
282
+ === Roll your own conditions
254
283
 
255
284
  I didn't include this function because its MySQL specific, and it's probably rarely used, but MySQL supports a "SOUNDS LIKE" function.
256
285
 
@@ -258,7 +287,7 @@ I want to use it, so let's add it:
258
287
 
259
288
  # config/initializers/searchgasm.rb
260
289
  # Actual function for MySQL databases only
261
- class SoundsLikeCondition < Searchgasm::Condition
290
+ class SoundsLike < Searchgasm::Condition::Base
262
291
  class << self
263
292
  # I pass you the column, you tell me what you want the method to be called.
264
293
  # If you don't want to add this condition for that column, return nil
@@ -281,21 +310,25 @@ I want to use it, so let's add it:
281
310
  end
282
311
  end
283
312
 
284
- Searchgasm::Condition.register_condition(SoundsLikeCondition)
313
+ Searchgasm::Conditions::Base.register_condition(SoundsLike)
285
314
 
286
315
  Now test it out:
287
316
 
288
317
  search = User.new_search
289
- search.first_name_sounds_like = "Ben"
318
+ search.conditions.first_name_sounds_like = "Ben"
290
319
  search.all # will return any user that has a first name that sounds like "Ben"
291
320
 
292
- Pretty nifty, huh? You can create any condition ultimately creating any SQL you want. The sky is the limit.
321
+ Pretty nifty, huh? You can create any condition ultimately creating any SQL you want. The sky is the limit. For more information see Searchgasm::Condition::Base
322
+
323
+ == Reporting problems / bugs
324
+
325
+ http://binarylogic.lighthouseapp.com/projects/16601-searchgasm
293
326
 
294
- ## Credits
327
+ == Credits
295
328
 
296
329
  Author: [Ben Johnson](http://github.com/binarylogic) of [Binary Logic](http://www.binarylogic.com)
297
330
 
298
- Credit to [Zack Ham](http://github.com/zackham) and [Robert Malko](http://github.com/malkomalko/) for helping with feature suggestions, cleaning up the readme / wiki, and cleaning up my code.
331
+ Credit to [Zack Ham](http://github.com/zackham) and [Robert Malko](http://github.com/malkomalko/) for helping with feature suggestions.
299
332
 
300
333
 
301
334
  Copyright (c) 2008 [Ben Johnson](http://github.com/binarylogic) of [Binary Logic](http://www.binarylogic.com), released under the MIT license
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'echoe'
4
4
  require File.dirname(__FILE__) << "/lib/searchgasm/version"
5
5
 
6
6
  Echoe.new 'searchgasm' do |p|
7
- p.version = BinaryLogic::Searchgasm::Version::STRING
7
+ p.version = Searchgasm::Version::STRING
8
8
  p.author = "Ben Johnson of Binary Logic"
9
9
  p.email = 'bjohnson@binarylogic.com'
10
10
  p.project = 'searchgasm'
@@ -0,0 +1,4 @@
1
+ === Live example
2
+
3
+ * Please see the live example: http://searchgasm_example.binarylogic.com
4
+ * Source / Github project for the example: http://github.com/binarylogic/searchgasm_example.binarylogic.com
@@ -1,53 +1,51 @@
1
- module BinaryLogic
2
- module Searchgasm
3
- module ActiveRecord
4
- module Associations
5
- module AssociationCollection
6
- def find_with_searchgasm(*args)
7
- options = args.extract_options!
8
- args << sanitize_options_with_searchgasm(options)
9
- find_without_searchgasm(*args)
10
- end
11
-
12
- def build_conditions(options = {}, &block)
13
- conditions = @reflection.klass.build_conditions(options, &block)
14
- conditions.scope = scope(:find)[:conditions]
15
- conditions
16
- end
17
-
18
- def build_conditions!(options = {}, &block)
19
- conditions = @reflection.klass.build_conditions!(options, &block)
20
- conditions.scope = scope(:find)[:conditions]
21
- conditions
22
- end
1
+ module Searchgasm
2
+ module ActiveRecord
3
+ module Associations
4
+ module AssociationCollection
5
+ def find_with_searchgasm(*args)
6
+ options = args.extract_options!
7
+ args << sanitize_options_with_searchgasm(options)
8
+ find_without_searchgasm(*args)
9
+ end
10
+
11
+ def build_conditions(options = {}, &block)
12
+ conditions = @reflection.klass.build_conditions(options, &block)
13
+ conditions.scope = scope(:find)[:conditions]
14
+ conditions
15
+ end
23
16
 
24
- def build_search(options = {}, &block)
25
- conditions = @reflection.klass.build_search(options, &block)
26
- conditions.scope = scope(:find)[:conditions]
27
- conditions
28
- end
29
-
30
- def build_search!(options = {}, &block)
31
- conditions = @reflection.klass.build_search!(options, &block)
32
- conditions.scope = scope(:find)[:conditions]
33
- conditions
34
- end
17
+ def build_conditions!(options = {}, &block)
18
+ conditions = @reflection.klass.build_conditions!(options, &block)
19
+ conditions.scope = scope(:find)[:conditions]
20
+ conditions
35
21
  end
36
22
 
37
- module HasManyAssociation
38
- def count_with_searchgasm(*args)
39
- column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
40
- count_without_searchgasm(column_name, sanitize_options_with_searchgasm(options))
41
- end
23
+ def build_search(options = {}, &block)
24
+ conditions = @reflection.klass.build_search(options, &block)
25
+ conditions.scope = scope(:find)[:conditions]
26
+ conditions
27
+ end
28
+
29
+ def build_search!(options = {}, &block)
30
+ conditions = @reflection.klass.build_search!(options, &block)
31
+ conditions.scope = scope(:find)[:conditions]
32
+ conditions
33
+ end
34
+ end
35
+
36
+ module HasManyAssociation
37
+ def count_with_searchgasm(*args)
38
+ column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
39
+ count_without_searchgasm(column_name, sanitize_options_with_searchgasm(options))
42
40
  end
43
41
  end
44
42
  end
45
43
  end
46
44
  end
47
45
 
48
- ActiveRecord::Associations::AssociationCollection.send(:include, BinaryLogic::Searchgasm::ActiveRecord::Associations::AssociationCollection)
46
+ ActiveRecord::Associations::AssociationCollection.send(:include, Searchgasm::ActiveRecord::Associations::AssociationCollection)
49
47
 
50
- module ::ActiveRecord
48
+ module ActiveRecord
51
49
  module Associations
52
50
  class AssociationCollection
53
51
  alias_method_chain :find, :searchgasm
@@ -55,9 +53,9 @@ module ::ActiveRecord
55
53
  end
56
54
  end
57
55
 
58
- ActiveRecord::Associations::HasManyAssociation.send(:include, BinaryLogic::Searchgasm::ActiveRecord::Associations::HasManyAssociation)
56
+ ActiveRecord::Associations::HasManyAssociation.send(:include, Searchgasm::ActiveRecord::Associations::HasManyAssociation)
59
57
 
60
- module ::ActiveRecord
58
+ module ActiveRecord
61
59
  module Associations
62
60
  class HasManyAssociation
63
61
  alias_method_chain :count, :searchgasm