searchgasm 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.4.1 released 2008-10-08
2
+
3
+ * Extracted english text into configuration to support alternate languages. I18n support.
4
+ * Improved method detection in add_joins to use respond_to? with the private method option set to true
5
+
1
6
  == 1.4.0 released 2008-10-08
2
7
 
3
8
  * Fixed bug when duping or cloning to copy over instance vars instead of method values
@@ -175,8 +175,7 @@ module ActiveRecord #:nodoc: all
175
175
  #
176
176
  # Where as before, the only way to get the above query to work would be to include line_items also, which is not neccessarily what you want.
177
177
  def add_joins!(sql, options_or_joins, scope = :auto) # :nodoc:
178
- code_type = array_of_strings?([""]) && :array_of_strings rescue nil
179
- code_type ||= merge_joins("", "") && :merge_joins rescue nil
178
+ code_type = (respond_to?(:array_of_strings?, true) && :array_of_strings) || (respond_to?(:merge_joins, true) && :merge_joins)
180
179
 
181
180
  case code_type
182
181
  when :array_of_strings, :merge_joins
@@ -154,6 +154,55 @@ module Searchgasm
154
154
  @per_page_choices = value
155
155
  end
156
156
 
157
+ def per_page_show_all_text # :nodoc:
158
+ @per_page_show_all_text ||= "Show all"
159
+ end
160
+
161
+ # The default value for the :text option for per_page_links and per_page_select when the page is nil, meaning show all.
162
+ #
163
+ # * <tt>Default:</tt> "Show all"
164
+ # * <tt>Accepts:</tt> String
165
+ def per_page_show_all_text=(value)
166
+ @per_page_show_all_text = value
167
+ end
168
+
169
+ def per_page_text # :nodoc:
170
+ @per_page_text ||= "%s per page"
171
+ end
172
+
173
+ # The default value for the :text option for per_page_links and per_page_select when the page is NOT nil. Only one substitution is
174
+ # passed, which is the per_page value.
175
+ #
176
+ # * <tt>Default:</tt> "%s per page"
177
+ # * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
178
+ def per_page_text=(value)
179
+ @per_page_text = value
180
+ end
181
+
182
+ def priority_order_by_link_activate_text # :nodoc:
183
+ @priority_order_by_link_activate_text ||= "Show %s first"
184
+ end
185
+
186
+ # The default value for the :activate_text option for priority_order_by_link
187
+ #
188
+ # * <tt>Default:</tt> "Show %s first"
189
+ # * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
190
+ def priority_order_by_link_activate_text=(value)
191
+ @priority_order_by_link_activate_text = value
192
+ end
193
+
194
+ def priority_order_by_link_deactivate_text # :nodoc:
195
+ @priority_order_by_link_deactivate_text ||= "Don't show %s first"
196
+ end
197
+
198
+ # The default value for the :deactivate_text option for priority_order_by_link
199
+ #
200
+ # * <tt>Default:</tt> "Dont' show %s first"
201
+ # * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
202
+ def priority_order_by_link_deactivate_text=(value)
203
+ @priority_order_by_link_deactivate_text = value
204
+ end
205
+
157
206
  def remove_duplicates # :nodoc:
158
207
  return @remove_duplicates if @set_remove_duplicates
159
208
  @remove_duplicates ||= true
@@ -181,7 +181,8 @@ module Searchgasm
181
181
  # As you can see above, passing nil means "show all" and the text will automatically revert to "show all"
182
182
  #
183
183
  # === Options
184
- # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
184
+ # * <tt>:text</tt> -- default: "%s per page", text for the link, only if per_page is not blank
185
+ # * <tt>:show_all_text</tt> -- default: "Show all", text for the link, only if per_page is blank
185
186
  # * <tt>:html</tt> -- html arrtributes for the <a> tag.
186
187
  #
187
188
  # === Advanced Options
@@ -259,8 +260,8 @@ module Searchgasm
259
260
  def add_priority_order_by_link_defaults!(priority_order_by, priority_order_as, options = {})
260
261
  add_searchgasm_control_defaults!(:priority_order_by, options)
261
262
  options[:column_name] ||= determine_order_by_text(priority_order_by).downcase
262
- options[:activate_text] ||= "Show #{options[:column_name]} first"
263
- options[:deactivate_text] ||= "Don't show #{options[:column_name]} first"
263
+ options[:activate_text] ||= Config.priority_order_by_link_activate_text % options[:column_name]
264
+ options[:deactivate_text] ||= Config.priority_order_by_link_deactivate_text % options[:column_name]
264
265
  active = deep_stringify(options[:search_obj].priority_order_by) == deep_stringify(priority_order_by) && options[:search_obj].priority_order_as == priority_order_as
265
266
  options[:text] ||= active ? options[:deactivate_text] : options[:activate_text]
266
267
  if active
@@ -274,7 +275,8 @@ module Searchgasm
274
275
 
275
276
  def add_per_page_link_defaults!(per_page, options = {})
276
277
  add_searchgasm_control_defaults!(:per_page, options)
277
- options[:text] ||= per_page.blank? ? "Show all" : "#{per_page} per page"
278
+ options[:show_all_text] ||= Config.per_page_show_all_text
279
+ options[:text] ||= per_page.blank? ? options[:show_all_text] : Config.per_page.text % per_page
278
280
  options[:url] = searchgasm_params(options.merge(:search_params => {:per_page => per_page}))
279
281
  options
280
282
  end
@@ -44,7 +44,9 @@ module Searchgasm
44
44
 
45
45
  def add_per_page_select_defaults!(options)
46
46
  add_per_page_links_defaults!(options)
47
- options[:choices] = options[:choices].collect { |choice| choice.nil? ? ["Show all", choice] : ["#{choice} per page", choice]}
47
+ options[:show_all_text] ||= Config.per_page_show_all_text
48
+ options[:text] ||= Config.per_page_text
49
+ options[:choices] = options[:choices].collect { |choice| choice.nil? ? [options[:show_all_text], choice] : [options[:text] % choice, choice]}
48
50
  add_searchgasm_select_defaults!(:per_page, options)
49
51
  options
50
52
  end
@@ -83,24 +83,9 @@ module Searchgasm #:nodoc:
83
83
  # Merges all joins together, including the scopes joins for
84
84
  def joins
85
85
  all_joins = (safe_to_array(conditions.auto_joins) + safe_to_array(order_by_auto_joins) + safe_to_array(priority_order_by_auto_joins) + safe_to_array(@joins)).uniq
86
- # For partial backwards compatibility, delete if the scope contains conflicts, AR 2.2 does this for you
87
- scope_joins = safe_to_array(scope && scope[:joins])
88
- all_joins.delete_if { |j| scope_joins.include?(j) } unless scope_joins.blank?
89
86
  all_joins.size <= 1 ? all_joins.first : all_joins
90
87
  end
91
- =begin
92
- def joins
93
- auto_joins = joins_to_sql_array((safe_to_array(conditions.auto_joins) + safe_to_array(order_by_auto_joins) + safe_to_array(priority_order_by_auto_joins)).uniq)
94
- scope_joins = joins_to_sql_array(scope && scope[:joins])
95
- include_joins = joins_to_sql_array(include)
96
-
97
- #raise auto_joins.inspect if conditions.respond_to?(:dogs) && conditions.dogs.id == 1
98
-
99
- auto_joins.delete_if { |auto_join| scope_joins.include?(auto_join) || include_joins.include?(auto_join) }
100
-
101
- #raise auto_joins.inspect if auto_joins.size > 1
102
- end
103
- =end
88
+
104
89
  def limit=(value)
105
90
  @set_limit = true
106
91
  @limit = value.blank? || value == 0 ? nil : value.to_i
@@ -134,20 +119,16 @@ module Searchgasm #:nodoc:
134
119
  find_options
135
120
  end
136
121
 
122
+ def select
123
+ @select ||= "DISTINCT #{klass.connection.quote_table_name(klass.table_name)}.*" if !joins.blank? && Config.remove_duplicates?
124
+ @select
125
+ end
126
+
137
127
  def scope
138
128
  @scope ||= {}
139
129
  end
140
130
 
141
131
  private
142
- def joins_to_sql_array(joins)
143
- unless array_of_strings?(safe_to_array(joins))
144
- join_dependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency.new(klass, joins, nil)
145
- join_dependency.join_associations.collect { |assoc| assoc.association_join }
146
- else
147
- joins.is_a?(Array) ? joins : safe_to_array(joins)
148
- end
149
- end
150
-
151
132
  def safe_to_array(o)
152
133
  case o
153
134
  when NilClass
@@ -21,9 +21,7 @@ module Searchgasm
21
21
  args[0] = klass.primary_key if [nil, :all].include?(args[0])
22
22
  end
23
23
  args << options
24
- result = klass.#{method}(*args)
25
- result.uniq! if result.is_a?(Array) && Config.remove_duplicates?
26
- result
24
+ klass.#{method}(*args)
27
25
  end
28
26
  end
29
27
  end_eval
@@ -67,7 +67,7 @@ module Searchgasm
67
67
 
68
68
  MAJOR = 1
69
69
  MINOR = 4
70
- TINY = 0
70
+ TINY = 1
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/searchgasm.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
 
2
- # Gem::Specification for Searchgasm-1.4.0
2
+ # Gem::Specification for Searchgasm-1.4.1
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: searchgasm
7
7
  version: !ruby/object:Gem::Version
8
- version: 1.4.0
8
+ version: 1.4.1
9
9
  platform: ruby
10
10
  authors:
11
11
  - Ben Johnson of Binary Logic
@@ -45,6 +45,7 @@ class TestActiveRecordBase < Test::Unit::TestCase
45
45
  assert_equal Account.find(1, 3), Account.all(:conditions => {:name_contains => "Binary"})
46
46
  assert_equal [Account.find(1)], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben"}})
47
47
  assert_equal [], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben", :last_name => "Mills"}})
48
+ assert_equal Account.find(1, 2), Account.all(:conditions => {:users => {:id_gt => 0}}, :include => :users)
48
49
 
49
50
  read_only_accounts = Account.all(:conditions => {:name_contains => "Binary"}, :readonly => true)
50
51
  assert read_only_accounts.first.readonly?
@@ -98,23 +98,23 @@ class TestSearchBase < Test::Unit::TestCase
98
98
  search.lock = true
99
99
  assert_equal search.lock, true
100
100
  end
101
- =begin
102
- def test_auto_joins
101
+
102
+ def test_joins
103
103
  search = Account.new_search
104
- assert_equal nil, search.auto_joins
104
+ assert_equal nil, search.joins
105
105
  search.conditions.name_contains = "Binary"
106
- assert_equal nil, search.auto_joins
106
+ assert_equal nil, search.joins
107
107
  search.conditions.users.first_name_contains = "Ben"
108
- assert_equal(:users, search.auto_joins)
108
+ assert_equal(:users, search.joins)
109
109
  search.conditions.users.orders.id_gt = 2
110
- assert_equal({:users => :orders}, search.auto_joins)
110
+ assert_equal({:users => :orders}, search.joins)
111
111
  search.conditions.users.reset_orders!
112
- assert_equal(:users, search.auto_joins)
112
+ assert_equal(:users, search.joins)
113
113
  search.conditions.users.orders.id_gt = 2
114
114
  search.conditions.reset_users!
115
- assert_equal nil, search.auto_joins
115
+ assert_equal nil, search.joins
116
116
  end
117
- =end
117
+
118
118
  def test_limit
119
119
  search = Account.new_search
120
120
  search.limit = 10
@@ -141,7 +141,7 @@ class TestSearchBase < Test::Unit::TestCase
141
141
  search.conditions.users.id_greater_than = 2
142
142
  search.page = 3
143
143
  search.readonly = true
144
- assert_equal({:joins => :users, :offset => 4, :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2], :limit => 2 }, search.sanitize)
144
+ assert_equal({:joins => :users, :offset => 4, :select => "DISTINCT \"accounts\".*", :readonly => true, :conditions => ["(\"accounts\".\"name\" LIKE ?) AND (\"users\".\"id\" > ?)", "%Binary%", 2], :limit => 2 }, search.sanitize)
145
145
  end
146
146
 
147
147
  def test_scope
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchgasm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic