Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated searchgasm

  • Loading branch information...
commit 82b98b21d1f6edaf2fa6d6114d1db218ba50b590 1 parent 2e40657
@binarylogic authored
Showing with 6,112 additions and 4,632 deletions.
  1. +5 −1 app/models/user.rb
  2. +1 −1  config/environment.rb
  3. +1 −1  config/initializers/searchgasm.rb
  4. +13 −0 db/migrate/20081015223630_add_settings_table.rb
  5. +33 −1 vendor/plugins/searchgasm/CHANGELOG.rdoc
  6. +14 −3 vendor/plugins/searchgasm/Manifest
  7. +11 −0 vendor/plugins/searchgasm/README.rdoc
  8. +1 −1  vendor/plugins/searchgasm/Rakefile
  9. +4 −1 vendor/plugins/searchgasm/TODO.rdoc
  10. +4 −2 vendor/plugins/searchgasm/lib/searchgasm.rb
  11. +25 −14 vendor/plugins/searchgasm/lib/searchgasm/active_record/associations.rb
  12. +50 −1 vendor/plugins/searchgasm/lib/searchgasm/active_record/base.rb
  13. +20 −0 vendor/plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/mysql_adapter.rb
  14. +20 −0 vendor/plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/postgresql_adapter.rb
  15. +21 −0 vendor/plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/sqlite_adapter.rb
  16. +37 −12 vendor/plugins/searchgasm/lib/searchgasm/condition/base.rb
  17. +2 −0  vendor/plugins/searchgasm/lib/searchgasm/condition/begins_with.rb
  18. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/child_of.rb
  19. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/descendant_of.rb
  20. +2 −0  vendor/plugins/searchgasm/lib/searchgasm/condition/ends_with.rb
  21. +2 −2 vendor/plugins/searchgasm/lib/searchgasm/condition/inclusive_descendant_of.rb
  22. +3 −0  vendor/plugins/searchgasm/lib/searchgasm/condition/keywords.rb
  23. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/not_begin_with.rb
  24. +17 −0 vendor/plugins/searchgasm/lib/searchgasm/condition/not_blank.rb
  25. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/not_end_with.rb
  26. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/not_equal.rb
  27. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/not_have_keywords.rb
  28. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/not_like.rb
  29. +17 −0 vendor/plugins/searchgasm/lib/searchgasm/condition/not_nil.rb
  30. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/condition/sibling_of.rb
  31. +2 −0  vendor/plugins/searchgasm/lib/searchgasm/condition/tree.rb
  32. +9 −7 vendor/plugins/searchgasm/lib/searchgasm/conditions/base.rb
  33. +1 −1  vendor/plugins/searchgasm/lib/searchgasm/conditions/protection.rb
  34. +9 −158 vendor/plugins/searchgasm/lib/searchgasm/config.rb
  35. +279 −0 vendor/plugins/searchgasm/lib/searchgasm/config/helpers.rb
  36. +53 −0 vendor/plugins/searchgasm/lib/searchgasm/config/search.rb
  37. +26 −22 vendor/plugins/searchgasm/lib/searchgasm/helpers/control_types/link.rb
  38. +59 −30 vendor/plugins/searchgasm/lib/searchgasm/helpers/control_types/links.rb
  39. +5 −2 vendor/plugins/searchgasm/lib/searchgasm/helpers/control_types/select.rb
  40. +3 −3 vendor/plugins/searchgasm/lib/searchgasm/helpers/form.rb
  41. +3 −4 vendor/plugins/searchgasm/lib/searchgasm/helpers/utilities.rb
  42. +15 −0 vendor/plugins/searchgasm/lib/searchgasm/modifiers/lower.rb
  43. +15 −0 vendor/plugins/searchgasm/lib/searchgasm/modifiers/ltrim.rb
  44. +15 −0 vendor/plugins/searchgasm/lib/searchgasm/modifiers/rtrim.rb
  45. +15 −0 vendor/plugins/searchgasm/lib/searchgasm/modifiers/trim.rb
  46. +15 −0 vendor/plugins/searchgasm/lib/searchgasm/modifiers/upper.rb
  47. +30 −25 vendor/plugins/searchgasm/lib/searchgasm/search/base.rb
  48. +0 −16 vendor/plugins/searchgasm/lib/searchgasm/search/conditions.rb
  49. +1 −9 vendor/plugins/searchgasm/lib/searchgasm/search/ordering.rb
  50. +2 −10 vendor/plugins/searchgasm/lib/searchgasm/search/searching.rb
  51. +2 −2 vendor/plugins/searchgasm/lib/searchgasm/version.rb
  52. +3 −0  vendor/plugins/searchgasm/test/fixtures/cats.yml
  53. +3 −0  vendor/plugins/searchgasm/test/fixtures/dogs.yml
  54. +7 −0 vendor/plugins/searchgasm/test/test_active_record_base.rb
  55. +4 −4 vendor/plugins/searchgasm/test/test_condition_base.rb
  56. +27 −27 vendor/plugins/searchgasm/test/test_condition_types.rb
  57. +22 −1 vendor/plugins/searchgasm/test/test_conditions_base.rb
  58. +2 −4 vendor/plugins/searchgasm/test/test_config.rb
  59. +26 −5 vendor/plugins/searchgasm/test/test_helper.rb
  60. +18 −23 vendor/plugins/searchgasm/test/test_search_base.rb
  61. +1 −11 vendor/plugins/searchgasm/test/test_search_conditions.rb
  62. +3 −4 vendor/plugins/searchgasm/test/test_search_ordering.rb
  63. +1 −1  vendor/plugins/searchgasm/test/test_search_pagination.rb
  64. 0  vendor/plugins/searchgasm/{test/libs → test_libs}/acts_as_tree.rb
  65. 0  vendor/plugins/searchgasm/{test/libs → test_libs}/ordered_hash.rb
  66. 0  vendor/plugins/searchgasm/{test/libs → test_libs}/rexml_fix.rb
  67. +3 −0  vendor/rails/actionmailer/lib/action_mailer/base.rb
  68. +1 −1  vendor/rails/actionmailer/lib/action_mailer/version.rb
  69. +2 −0  vendor/rails/actionmailer/test/abstract_unit.rb
  70. +2 −0  vendor/rails/actionmailer/test/fixtures/test_mailer/body_ivar.erb
  71. +12 −0 vendor/rails/actionmailer/test/mail_service_test.rb
  72. +10 −0 vendor/rails/actionpack/CHANGELOG
  73. +21 −16 vendor/rails/actionpack/lib/action_controller/base.rb
  74. +2 −22 vendor/rails/actionpack/lib/action_controller/cgi_ext/session.rb
  75. +29 −1 vendor/rails/actionpack/lib/action_controller/dispatcher.rb
  76. +1 −1  vendor/rails/actionpack/lib/action_controller/integration.rb
  77. +2 −3 vendor/rails/actionpack/lib/action_controller/request.rb
  78. +17 −113 vendor/rails/actionpack/lib/action_controller/rescue.rb
  79. +1 −3 vendor/rails/actionpack/lib/action_controller/routing/builder.rb
  80. +4 −1 vendor/rails/actionpack/lib/action_controller/test_case.rb
  81. +1 −1  vendor/rails/actionpack/lib/action_pack/version.rb
  82. +1 −1  vendor/rails/actionpack/lib/action_view.rb
  83. +10 −8 vendor/rails/actionpack/lib/action_view/base.rb
  84. +0 −1  vendor/rails/actionpack/lib/action_view/helpers.rb
  85. +316 −148 vendor/rails/actionpack/lib/action_view/helpers/asset_tag_helper.rb
  86. +56 −8 vendor/rails/actionpack/lib/action_view/helpers/atom_feed_helper.rb
  87. +0 −92 vendor/rails/actionpack/lib/action_view/helpers/form_country_helper.rb
  88. +4 −4 vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
  89. +0 −3  vendor/rails/actionpack/lib/action_view/helpers/form_options_helper.rb
  90. +12 −5 vendor/rails/actionpack/lib/action_view/helpers/form_tag_helper.rb
  91. +6 −12 vendor/rails/actionpack/lib/action_view/helpers/prototype_helper.rb
  92. +80 −126 vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb
  93. +9 −4 vendor/rails/actionpack/lib/action_view/template.rb
  94. +10 −20 vendor/rails/actionpack/lib/action_view/template_error.rb
  95. +1 −1  vendor/rails/actionpack/test/abstract_unit.rb
  96. +46 −1 vendor/rails/actionpack/test/controller/render_test.rb
  97. +11 −24 vendor/rails/actionpack/test/controller/rescue_test.rb
  98. +21 −0 vendor/rails/actionpack/test/controller/routing_test.rb
  99. +1 −0  vendor/rails/actionpack/test/controller/test_test.rb
  100. +1 −0  vendor/rails/actionpack/test/fixtures/test/sub_template_raise.html.erb
  101. +73 −4 vendor/rails/actionpack/test/template/asset_tag_helper_test.rb
  102. +81 −0 vendor/rails/actionpack/test/template/atom_feed_helper_test.rb
  103. +0 −1,549 vendor/rails/actionpack/test/template/form_country_helper_test.rb
  104. +8 −1 vendor/rails/actionpack/test/template/form_tag_helper_test.rb
  105. +3 −3 vendor/rails/actionpack/test/template/prototype_helper_test.rb
  106. +17 −1 vendor/rails/actionpack/test/template/render_test.rb
  107. +2 −0  vendor/rails/activerecord/CHANGELOG
  108. +2 −2 vendor/rails/activerecord/lib/active_record.rb
  109. +2 −2 vendor/rails/activerecord/lib/active_record/aggregations.rb
  110. +107 −18 vendor/rails/activerecord/lib/active_record/association_preload.rb
  111. +52 −19 vendor/rails/activerecord/lib/active_record/associations.rb
  112. +23 −7 vendor/rails/activerecord/lib/active_record/associations/association_collection.rb
  113. +12 −1 vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb
  114. +13 −2 vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb
  115. +1 −1  vendor/rails/activerecord/lib/active_record/associations/has_one_association.rb
  116. +9 −1 vendor/rails/activerecord/lib/active_record/attribute_methods.rb
  117. +159 −43 vendor/rails/activerecord/lib/active_record/base.rb
  118. +8 −4 vendor/rails/activerecord/lib/active_record/calculations.rb
  119. +89 −18 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  120. +22 −5 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
  121. +8 −2 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  122. +31 −18 vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  123. +3 −3 vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  124. +4 −4 vendor/rails/activerecord/lib/active_record/dynamic_finder_match.rb
  125. +26 −0 vendor/rails/activerecord/lib/active_record/i18n_interpolation_deprecation.rb
  126. +82 −53 vendor/rails/activerecord/lib/active_record/reflection.rb
  127. +69 −18 vendor/rails/activerecord/lib/active_record/transactions.rb
  128. +66 −6 vendor/rails/activerecord/lib/active_record/validations.rb
  129. +1 −1  vendor/rails/activerecord/lib/active_record/version.rb
  130. +5 −0 vendor/rails/activerecord/test/cases/active_schema_test_mysql.rb
  131. +10 −13 vendor/rails/activerecord/test/cases/associations/belongs_to_associations_test.rb
  132. +57 −1 vendor/rails/activerecord/test/cases/associations/eager_test.rb
  133. +15 −0 vendor/rails/activerecord/test/cases/associations/extension_test.rb
  134. +10 −1 vendor/rails/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  135. +23 −0 vendor/rails/activerecord/test/cases/associations/has_many_associations_test.rb
  136. +25 −1 vendor/rails/activerecord/test/cases/associations/has_many_through_associations_test.rb
  137. +10 −0 vendor/rails/activerecord/test/cases/associations/has_one_associations_test.rb
  138. +10 −0 vendor/rails/activerecord/test/cases/associations/has_one_through_associations_test.rb
  139. +0 −12 vendor/rails/activerecord/test/cases/associations_test.rb
  140. +47 −4 vendor/rails/activerecord/test/cases/attribute_methods_test.rb
  141. +49 −7 vendor/rails/activerecord/test/cases/base_test.rb
  142. +3 −3 vendor/rails/activerecord/test/cases/calculations_test.rb
  143. +35 −7 vendor/rails/activerecord/test/cases/finder_test.rb
  144. +30 −0 vendor/rails/activerecord/test/cases/method_scoping_test.rb
  145. +6 −0 vendor/rails/activerecord/test/cases/named_scope_test.rb
  146. +4 −0 vendor/rails/activerecord/test/cases/reflection_test.rb
  147. +20 −0 vendor/rails/activerecord/test/cases/reload_models_test.rb
  148. +4 −4 vendor/rails/activerecord/test/cases/sanitize_test.rb
  149. +5 −1 vendor/rails/activerecord/test/cases/validations_i18n_test.rb
  150. +2 −0  vendor/rails/activerecord/test/models/author.rb
  151. +6 −0 vendor/rails/activerecord/test/models/club.rb
  152. +12 −1 vendor/rails/activerecord/test/models/company.rb
  153. +3 −0  vendor/rails/activerecord/test/models/post.rb
  154. +2 −0  vendor/rails/activeresource/CHANGELOG
  155. +38 −1 vendor/rails/activeresource/lib/active_resource/base.rb
  156. +1 −1  vendor/rails/activeresource/lib/active_resource/connection.rb
  157. +1 −1  vendor/rails/activeresource/lib/active_resource/formats/json_format.rb
  158. +24 −0 vendor/rails/activeresource/test/base_test.rb
  159. +10 −2 vendor/rails/activeresource/test/connection_test.rb
  160. +17 −0 vendor/rails/activeresource/test/format_test.rb
  161. +8 −0 vendor/rails/activesupport/CHANGELOG
  162. +147 −0 vendor/rails/activesupport/bin/generate_tables
  163. +3 −1 vendor/rails/activesupport/lib/active_support.rb
  164. +13 −2 vendor/rails/activesupport/lib/active_support/base64.rb
  165. +1 −1  vendor/rails/activesupport/lib/active_support/buffered_logger.rb
  166. +9 −9 vendor/rails/activesupport/lib/active_support/core_ext/array/access.rb
  167. +2 −1  vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb
  168. +3 −0  vendor/rails/activesupport/lib/active_support/core_ext/base64/encoding.rb
  169. +2 −0  vendor/rails/activesupport/lib/active_support/core_ext/float.rb
  170. +27 −0 vendor/rails/activesupport/lib/active_support/core_ext/float/time.rb
  171. +1 −1  vendor/rails/activesupport/lib/active_support/core_ext/hash/slice.rb
  172. +2 −0  vendor/rails/activesupport/lib/active_support/core_ext/integer.rb
  173. +45 −0 vendor/rails/activesupport/lib/active_support/core_ext/integer/time.rb
  174. +0 −10 vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb
  175. +33 −12 vendor/rails/activesupport/lib/active_support/core_ext/object/extending.rb
  176. +36 −16 vendor/rails/activesupport/lib/active_support/core_ext/object/misc.rb
  177. +4 −2 vendor/rails/activesupport/lib/active_support/core_ext/string.rb
  178. +5 −5 vendor/rails/activesupport/lib/active_support/core_ext/string/access.rb
  179. +81 −0 vendor/rails/activesupport/lib/active_support/core_ext/string/multibyte.rb
  180. +0 −66 vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb
  181. +11 −1 vendor/rails/activesupport/lib/active_support/core_ext/time/calculations.rb
  182. +31 −5 vendor/rails/activesupport/lib/active_support/inflector.rb
  183. +1 −0  vendor/rails/activesupport/lib/active_support/locale/en-US.yml
  184. +7 −3 vendor/rails/activesupport/lib/active_support/memoizable.rb
  185. +31 −7 vendor/rails/activesupport/lib/active_support/multibyte.rb
  186. +664 −127 vendor/rails/activesupport/lib/active_support/multibyte/chars.rb
  187. +8 −0 vendor/rails/activesupport/lib/active_support/multibyte/exceptions.rb
  188. +0 −149 vendor/rails/activesupport/lib/active_support/multibyte/generators/generate_tables.rb
  189. +0 −9 vendor/rails/activesupport/lib/active_support/multibyte/handlers/passthru_handler.rb
  190. +0 −564 vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb
  191. +0 −43 vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler_proc.rb
  192. +71 −0 vendor/rails/activesupport/lib/active_support/multibyte/unicode_database.rb
  193. +108 −0 vendor/rails/activesupport/lib/active_support/rescuable.rb
  194. +2 −2 vendor/rails/activesupport/lib/active_support/secure_random.rb
  195. +7 −4 vendor/rails/activesupport/lib/active_support/testing/core_ext/test/unit/assertions.rb
  196. BIN  vendor/rails/activesupport/lib/active_support/values/unicode_tables.dat
  197. +17 −10 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n.rb
  198. +26 −11 vendor/rails/activesupport/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb
  199. +1 −1  vendor/rails/activesupport/lib/active_support/version.rb
  200. +19 −0 vendor/rails/activesupport/test/abstract_unit.rb
  201. +50 −0 vendor/rails/activesupport/test/core_ext/duration_test.rb
  202. +10 −0 vendor/rails/activesupport/test/core_ext/hash_ext_test.rb
  203. +53 −6 vendor/rails/activesupport/test/core_ext/string_ext_test.rb
  204. +9 −0 vendor/rails/activesupport/test/core_ext/time_ext_test.rb
  205. +16 −0 vendor/rails/activesupport/test/i18n_test.rb
  206. +6 −0 vendor/rails/activesupport/test/inflector_test.rb
  207. +6 −1 vendor/rails/activesupport/test/inflector_test_cases.rb
  208. +12 −12 vendor/rails/activesupport/test/json/encoding_test.rb
  209. +5 −0 vendor/rails/activesupport/test/memoizable_test.rb
  210. +544 −161 vendor/rails/activesupport/test/multibyte_chars_test.rb
  211. +44 −61 vendor/rails/activesupport/test/multibyte_conformance.rb
  212. +0 −372 vendor/rails/activesupport/test/multibyte_handler_test.rb
  213. +19 −0 vendor/rails/activesupport/test/multibyte_test_helpers.rb
  214. +28 −0 vendor/rails/activesupport/test/multibyte_unicode_database_test.rb
  215. +75 −0 vendor/rails/activesupport/test/rescuable_test.rb
  216. +4 −0 vendor/rails/activesupport/test/secure_random_test.rb
  217. +18 −0 vendor/rails/activesupport/test/test_test.rb
  218. +15 −7 vendor/rails/railties/Rakefile
  219. +62 −0 vendor/rails/railties/configs/databases/ibm_db.yml
  220. +2 −2 vendor/rails/railties/lib/console_sandbox.rb
  221. +1 −1  vendor/rails/railties/lib/initializer.rb
  222. +3 −3 vendor/rails/railties/lib/rails/gem_builder.rb
  223. +144 −31 vendor/rails/railties/lib/rails/gem_dependency.rb
  224. +1 −1  vendor/rails/railties/lib/rails/mongrel_server/commands.rb
  225. +1 −1  vendor/rails/railties/lib/rails/plugin.rb
  226. +140 −0 vendor/rails/railties/lib/rails/vendor_gem_source_index.rb
  227. +1 −1  vendor/rails/railties/lib/rails/version.rb
  228. +1 −0  vendor/rails/railties/lib/rails_generator/commands.rb
  229. +1 −1  vendor/rails/railties/lib/rails_generator/generators/applications/app/app_generator.rb
  230. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/controller/controller_generator.rb
  231. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb
  232. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb
  233. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/model/model_generator.rb
  234. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/observer/observer_generator.rb
  235. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb
  236. +1 −1  vendor/rails/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb
  237. +2 −2 vendor/rails/railties/lib/rails_generator/generators/components/resource/resource_generator.rb
  238. +2 −2 vendor/rails/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb
  239. +1 −1  vendor/rails/railties/lib/tasks/databases.rake
  240. +1 −0  vendor/rails/railties/lib/tasks/documentation.rake
  241. +22 −8 vendor/rails/railties/lib/tasks/gems.rake
  242. +65 −6 vendor/rails/railties/test/gem_dependency_test.rb
  243. +3 −0  vendor/rails/railties/test/generators/rails_controller_generator_test.rb
  244. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-a-0.4.0/.specification
  245. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-a-0.4.0/lib/dummy-gem-a.rb
  246. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-b-0.4.0/.specification
  247. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-b-0.4.0/lib/dummy-gem-b.rb
  248. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-b-0.6.0/.specification
  249. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-b-0.6.0/lib/dummy-gem-b.rb
  250. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-c-0.4.0/.specification
  251. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-c-0.4.0/lib/dummy-gem-c.rb
  252. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-c-0.6.0/.specification
  253. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-c-0.6.0/lib/dummy-gem-c.rb
  254. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-d-1.0.0/lib/dummy-gem-d.rb
  255. +28 −0 vendor/rails/railties/test/vendor/gems/dummy-gem-e-1.0.0/.specification
  256. +1 −0  vendor/rails/railties/test/vendor/gems/dummy-gem-e-1.0.0/lib/dummy-gem-e.rb
View
6 app/models/user.rb
@@ -1,4 +1,8 @@
class User < ActiveRecord::Base
belongs_to :user_group
- has_many :orders
+ has_many :orders, :dependent => :destroy
+
+ def name(middle_name = "")
+ "#{first_name} #{middle_name} #{last_name}"
+ end
end
View
2  config/environment.rb
@@ -46,7 +46,7 @@
config.time_zone = 'UTC'
#if RAILS_ENV == "development" # putting this in environments/development.rb doesn't work, not sure why
- # config.plugin_paths = ["#{RAILS_ROOT}/../../Libs"]
+ # config.plugin_paths += ["#{RAILS_ROOT}/../../Libs"]
# config.plugins = [:searchgasm]
# require "ruby-debug"
#end
View
2  config/initializers/searchgasm.rb
@@ -1,6 +1,6 @@
# Confugration
Searchgasm::Config.configure do |config|
- config.per_page = config.per_page_choices.first # 10
+ config.search.per_page = config.helpers.per_page_select_choices.first.last # 10
end
# Actual function for MySQL databases only
View
13 db/migrate/20081015223630_add_settings_table.rb
@@ -0,0 +1,13 @@
+class AddSettingsTable < ActiveRecord::Migration
+ def self.up
+ create_table :settings, :force => true do |t|
+ t.string :var, :null => false
+ t.text :value, :null => true
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :settings
+ end
+end
View
34 vendor/plugins/searchgasm/CHANGELOG.rdoc
@@ -1,4 +1,36 @@
-== 1.3.4 released 2008-10-03
+== 1.5.1 released 2008-10-20
+
+* Fixed bug with per_page_links
+* Added "ordering_by" class for per_page_links
+
+== 1.5.0 released 2008-10-20
+
+* Merge array of conditions with or or and where it makes sense. Begins with condition does not make sense to join with and, so instead join with or.
+* Cleaned up html validity so it will pass W3C validators
+* Restructure configuration to be more organized and allow for more configuration options.
+* Added more configuration options, especially for class names.
+
+== 1.4.1 released 2008-10-15
+
+* Extracted english text into configuration to support alternate languages. I18n support.
+* Improved method detection in add_joins to use respond_to? with the private method option set to true
+
+== 1.4.0 released 2008-10-15
+
+* Fixed bug when duping or cloning to copy over instance vars instead of method values
+* Fixed bug with older versions of ActiveRecord and creating an alias method chain on find in AssociationCollection
+* Added modifiers: upper, lower, trim, ltrim, rtrim
+* Added not_nil and not_blank conditions
+* Modified conditions so that table name is a variable, this allows table name to be switched on the fly.
+* Modified auto joins to return symbols instead of SQL. This allows AR to properly merge the joins and ultimately result in proper SQL when performing multiple complex scopes.
+* Fixed conflicts between includes and joins, duplicate joins are not added. Includes are prioritized. This also makes ActiveRecord much more flexible. Now you can cherry pick included associations. And not have to worry about conflicting with joins.
+* Modified ActiveRecord's default behavior to use inner joins with the :joins option. Inner joins impose limitations. When providing this as a "convenience", inner joins do not make sense. The don't allow OR conditions to be across associations, nor does it properly order when an ordering by an association attribute when that association is optional.
+
+== 1.3.5 released 2008-10-08
+
+* Since joins are now strings, AR doesn't know how to merge them properly. So searchgasm now checks which joins to skip over to avoid conflicts.
+
+== 1.3.4 released 2008-10-07
* Fixed method names creation for conditions with modifiers
* Create local column conditions, incase there are method conflicts. Such as "id".
View
17 vendor/plugins/searchgasm/Manifest
@@ -22,14 +22,18 @@ lib/searchgasm/condition/less_than_or_equal_to.rb
lib/searchgasm/condition/like.rb
lib/searchgasm/condition/nil.rb
lib/searchgasm/condition/not_begin_with.rb
+lib/searchgasm/condition/not_blank.rb
lib/searchgasm/condition/not_end_with.rb
lib/searchgasm/condition/not_equal.rb
lib/searchgasm/condition/not_have_keywords.rb
lib/searchgasm/condition/not_like.rb
+lib/searchgasm/condition/not_nil.rb
lib/searchgasm/condition/sibling_of.rb
lib/searchgasm/condition/tree.rb
lib/searchgasm/conditions/base.rb
lib/searchgasm/conditions/protection.rb
+lib/searchgasm/config/helpers.rb
+lib/searchgasm/config/search.rb
lib/searchgasm/config.rb
lib/searchgasm/core_ext/hash.rb
lib/searchgasm/helpers/control_types/link.rb
@@ -60,6 +64,8 @@ lib/searchgasm/modifiers/hour.rb
lib/searchgasm/modifiers/log.rb
lib/searchgasm/modifiers/log10.rb
lib/searchgasm/modifiers/log2.rb
+lib/searchgasm/modifiers/lower.rb
+lib/searchgasm/modifiers/ltrim.rb
lib/searchgasm/modifiers/md5.rb
lib/searchgasm/modifiers/microseconds.rb
lib/searchgasm/modifiers/milliseconds.rb
@@ -68,11 +74,14 @@ lib/searchgasm/modifiers/month.rb
lib/searchgasm/modifiers/octal.rb
lib/searchgasm/modifiers/radians.rb
lib/searchgasm/modifiers/round.rb
+lib/searchgasm/modifiers/rtrim.rb
lib/searchgasm/modifiers/second.rb
lib/searchgasm/modifiers/sign.rb
lib/searchgasm/modifiers/sin.rb
lib/searchgasm/modifiers/square_root.rb
lib/searchgasm/modifiers/tan.rb
+lib/searchgasm/modifiers/trim.rb
+lib/searchgasm/modifiers/upper.rb
lib/searchgasm/modifiers/week.rb
lib/searchgasm/modifiers/year.rb
lib/searchgasm/search/base.rb
@@ -90,12 +99,11 @@ MIT-LICENSE
Rakefile
README.rdoc
test/fixtures/accounts.yml
+test/fixtures/cats.yml
+test/fixtures/dogs.yml
test/fixtures/orders.yml
test/fixtures/user_groups.yml
test/fixtures/users.yml
-test/libs/acts_as_tree.rb
-test/libs/ordered_hash.rb
-test/libs/rexml_fix.rb
test/test_active_record_associations.rb
test/test_active_record_base.rb
test/test_condition_base.rb
@@ -109,4 +117,7 @@ test/test_search_conditions.rb
test/test_search_ordering.rb
test/test_search_pagination.rb
test/test_search_protection.rb
+test_libs/acts_as_tree.rb
+test_libs/ordered_hash.rb
+test_libs/rexml_fix.rb
TODO.rdoc
View
11 vendor/plugins/searchgasm/README.rdoc
@@ -305,6 +305,11 @@ Here are all of the available modifiers:
:md5 Converts to a MD5
:char_length :length The length of the string (integer)
+ :lower :downcase, :lcase Converts the string to all lower case characters
+ :ltrin :lstrip Strips off spaces from the beginning of the string
+ :trim :strip Strips off spaces from the beginning and end of the string
+ :rtrim :rstrip Strips off spaces from the end of the string
+ :upper :upcase, :ucase Converts the string to all upper case character
:absolute :abs The absolute value (-1 => 1)
:acos The arc cosine
@@ -344,6 +349,12 @@ Here's the cool part. Chaining modifiers:
As long as the modifier chain makes sense the possibilities are endless.
+=== Modifiers are not indexed
+
+Depending on your database you can create complex indexes. But chances are you probably didn't or don't plan to. So keep in mind that once you use a modifier it will not be using an index, meaning the query will be slower. One of the ways to get the best of both worlds is to cache virtual attributes in the database. Checkout my tutorial:
+
+http://www.binarylogic.com/2008/10/5/tutorial-caching-virtual-attributes-in-the-database
+
== Roll your own conditions & modifiers
For more information on this please see Searchgasm::Conditions::Base
View
2  vendor/plugins/searchgasm/Rakefile
@@ -10,6 +10,6 @@ Echoe.new 'searchgasm' do |p|
p.project = 'searchgasm'
p.summary = "Object based ActiveRecord searching, ordering, pagination, and more!"
p.url = "http://github.com/binarylogic/searchgasm"
- p.dependencies = %w(activerecord activesupport)
+ p.dependencies = %w(activerecord activesupport configatron)
p.include_rakefile = true
end
View
5 vendor/plugins/searchgasm/TODO.rdoc
@@ -1,3 +1,6 @@
= To Do
-1. Perform "more efficient" checks: year_of_created_at = 2008 and month_of_created_at = 8. Should result in a "BETWEEN" statement utilizing the column indexes. Thanks Georg for letting me know about this.
+1. Perform "more efficient" checks: year_of_created_at = 2008 and month_of_created_at = 8. Should result in a "BETWEEN" statement utilizing the column indexes. Thanks Georg for letting me know about this.
+2. Solve conflicts between scope joins and joins in the search (for old versions of AR). Also solve conflicts between joins and includes.
+3. Add configuration to change the "english" words
+4. Re-add the distinct option
View
6 vendor/plugins/searchgasm/lib/searchgasm.rb
@@ -21,6 +21,8 @@
# Base classes
require "searchgasm/version"
+require "searchgasm/config/helpers"
+require "searchgasm/config/search"
require "searchgasm/config"
# ActiveRecord
@@ -42,12 +44,12 @@
# Condition
require "searchgasm/condition/base"
require "searchgasm/condition/tree"
-SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :like, :nil, :not_begin_with, :not_end_with, :not_equal, :not_have_keywords, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
+SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :like, :nil, :not_begin_with, :not_blank, :not_end_with, :not_equal, :not_have_keywords, :not_nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
SEARCHGASM_CONDITIONS.each { |condition| require "searchgasm/condition/#{condition}" }
# Modifiers
require "searchgasm/modifiers/base"
-SEARCHGASM_MODIFIERS = [:day_of_month, :day_of_week, :day_of_year, :hour, :microseconds, :milliseconds, :minute, :month, :second, :week, :year]
+SEARCHGASM_MODIFIERS = [:absolute, :acos, :asin, :atan, :ceil, :char_length, :cos, :cot, :day_of_month, :day_of_week, :day_of_year, :degrees, :exp, :floor, :hex, :hour, :log, :log10, :log2, :lower, :ltrim, :md5, :microseconds, :milliseconds, :minute, :month, :octal, :radians, :round, :rtrim, :second, :sign, :sin, :square_root, :tan, :trim, :upper, :week, :year]
SEARCHGASM_MODIFIERS.each { |modifier| require "searchgasm/modifiers/#{modifier}" }
# Helpers
View
39 vendor/plugins/searchgasm/lib/searchgasm/active_record/associations.rb
@@ -13,7 +13,7 @@ def find_with_searchgasm(*args)
end
end
- module Shared
+ module HasManyAssociation
def count_with_searchgasm(*args)
options = args.extract_options!
args << filter_options_with_searchgasm(options)
@@ -24,18 +24,29 @@ def count_with_searchgasm(*args)
end
end
-module ActiveRecord
- module Associations
- class AssociationCollection
- include Searchgasm::ActiveRecord::Associations::AssociationCollection
-
- alias_method_chain :find, :searchgasm
- end
-
- class HasManyAssociation
- include Searchgasm::ActiveRecord::Associations::Shared
-
- alias_method_chain :count, :searchgasm
- end
+ActiveRecord::Associations::AssociationCollection.class_eval do
+ if respond_to?(:find)
+ include Searchgasm::ActiveRecord::Associations::AssociationCollection
+ alias_method_chain :find, :searchgasm
end
+end
+
+ActiveRecord::Associations::HasManyAssociation.class_eval do
+ include Searchgasm::ActiveRecord::Associations::HasManyAssociation
+ alias_method_chain :count, :searchgasm
+
+ # Older versions of AR have find in here, not in AssociationCollection
+ include Searchgasm::ActiveRecord::Associations::AssociationCollection
+ alias_method_chain :find, :searchgasm
+end
+
+ActiveRecord::Associations::ClassMethods::InnerJoinDependency::InnerJoinAssociation.class_eval do
+ private
+ # Inner joins impose limitations on queries. They can be quicker but you can't do OR conditions when conditions
+ # overlap from the base model to any of its associations. Also, inner joins won't allow you to order by an association
+ # attribute. What if the association is optional? All of those records are ommitted. It just doesn't make sense to default
+ # to inner joins when providing this as a "convenience" when searching. So let's change it.
+ def join_type
+ "LEFT OUTER JOIN"
+ end
end
View
51 vendor/plugins/searchgasm/lib/searchgasm/active_record/base.rb
@@ -108,6 +108,7 @@ def filter_options_with_searchgasm(options = {}, searching = true)
return options unless Searchgasm::Search::Base.needed?(self, options)
search = Searchgasm::Search::Base.create_virtual_class(self).new # call explicitly to avoid merging the scopes into the search
search.acting_as_filter = true
+ search.scope = scope(:find)
conditions = options.delete(:conditions) || options.delete("conditions") || {}
if conditions
case conditions
@@ -120,7 +121,7 @@ def filter_options_with_searchgasm(options = {}, searching = true)
search.options = options
search.sanitize(searching)
end
-
+
def searchgasm_search(options = {})
scope = {}
current_scope = scope(:find) && scope(:find).deep_dup
@@ -164,6 +165,54 @@ def valid_find_options
def valid_calculations_options
Calculations::CALCULATIONS_OPTIONS
end
+
+ private
+ # This is copied over from 2 different versions of ActiveRecord. I have to do this in order to preserve the "auto joins"
+ # as symbols. Keeping them as symbols allows ActiveRecord to merge them properly. The problem is when they conflict with includes.
+ # Includes add joins also, and they add them before joins do. So if they already added them skip them. Now you can do queries like:
+ #
+ # User.all(:joins => {:orders => :line_items}, :include => :orders)
+ #
+ # 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.
+ def add_joins!(sql, options_or_joins, scope = :auto) # :nodoc:
+ code_type = (respond_to?(:array_of_strings?, true) && :array_of_strings) || (respond_to?(:merge_joins, true) && :merge_joins)
+
+ case code_type
+ when :array_of_strings, :merge_joins
+ joins = options_or_joins
+ scope = scope(:find) if :auto == scope
+ merged_joins = scope && scope[:joins] && joins ? merge_joins(scope[:joins], joins) : (joins || scope && scope[:joins])
+ case merged_joins
+ when Symbol, Hash, Array
+ if code_type == :array_of_strings && array_of_strings?(merged_joins)
+ merged_joins.each { |merged_join| sql << " #{merged_join} " unless sql.include?(merged_join) }
+ else
+ join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, merged_joins, nil)
+ join_dependency.join_associations.each do |assoc|
+ join_sql = assoc.association_join
+ sql << " #{join_sql} " unless sql.include?(join_sql)
+ end
+ end
+ when String
+ sql << " #{merged_joins} " if merged_joins && !sql.include?(merged_joins)
+ end
+ else
+ options = options_or_joins
+ scope = scope(:find) if :auto == scope
+ [(scope && scope[:joins]), options[:joins]].each do |join|
+ case join
+ when Symbol, Hash, Array
+ join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, join, nil)
+ join_dependency.join_associations.each do |assoc|
+ join_sql = assoc.association_join
+ sql << " #{join_sql} " unless sql.include?(join_sql)
+ end
+ else
+ sql << " #{join} " if join && !sql.include?(join)
+ end
+ end
+ end
+ end
end
end
end
View
20 vendor/plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/mysql_adapter.rb
@@ -52,10 +52,30 @@ def char_length_sql(column_name)
"CHAR_LENGTH(#{column_name})"
end
+ def lower_sql(column_name)
+ "LOWER(#{column_name})"
+ end
+
+ def ltrim_sql(column_name)
+ "LTRIM(#{column_name})"
+ end
+
def md5_sql(column_name)
"MD5(#{column_name})"
end
+ def rtrim_sql(column_name)
+ "RTRIM(#{column_name})"
+ end
+
+ def trim_sql(column_name)
+ "TRIM(#{column_name})"
+ end
+
+ def upper_sql(column_name)
+ "UPPER(#{column_name})"
+ end
+
# Number functions
def absolute_sql(column_name)
"ABS(#{column_name})"
View
20 ...plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/postgresql_adapter.rb
@@ -52,10 +52,30 @@ def char_length_sql(column_name)
"length(#{column_name})"
end
+ def lower_sql(column_name)
+ "lower(#{column_name})"
+ end
+
+ def ltrim_sql(column_name)
+ "ltrim(#{column_name})"
+ end
+
def md5_sql(column_name)
"md5(#{column_name})"
end
+ def rtrim_sql(column_name)
+ "rtrim(#{column_name})"
+ end
+
+ def trim_sql(column_name)
+ "trim(#{column_name})"
+ end
+
+ def upper_sql(column_name)
+ "upper(#{column_name})"
+ end
+
# Number functions
def absolute_sql(column_name)
"abs(#{column_name})"
View
21 vendor/plugins/searchgasm/lib/searchgasm/active_record/connection_adapters/sqlite_adapter.rb
@@ -46,6 +46,27 @@ def month_sql(column_name)
def year_sql(column_name)
"strftime('%Y', #{column_name})"
end
+
+ # String functions
+ def lower_sql(column_name)
+ "lower(#{column_name})"
+ end
+
+ def ltrim_sql(column_name)
+ "ltrim(#{column_name})"
+ end
+
+ def rtrim_sql(column_name)
+ "rtrim(#{column_name})"
+ end
+
+ def trim_sql(column_name)
+ "trim(#{column_name})"
+ end
+
+ def upper_sql(column_name)
+ "upper(#{column_name})"
+ end
end
end
end
View
49 vendor/plugins/searchgasm/lib/searchgasm/condition/base.rb
@@ -7,8 +7,8 @@ module Condition # :nodoc:
class Base
include Shared::Utilities
- attr_accessor :column, :column_for_type_cast, :column_sql, :klass
- class_inheritable_accessor :handle_array_value, :ignore_meaningless_value, :value_type
+ attr_accessor :column, :column_for_type_cast, :column_sql, :column_sql_format, :klass, :table_name
+ class_inheritable_accessor :handle_array_value, :ignore_meaningless_value, :join_arrays_with_or, :value_type
self.ignore_meaningless_value = true
class << self
@@ -16,7 +16,7 @@ class << self
def condition_type_name
name.split("::").last.underscore
end
-
+
def handle_array_value?
handle_array_value == true
end
@@ -25,6 +25,10 @@ def ignore_meaningless_value? # :nodoc:
ignore_meaningless_value == true
end
+ def join_arrays_with_or?
+ join_arrays_with_or == true
+ end
+
# Determines what to call the condition for the model
#
# Searchgasm tries to create conditions on each model. Before it does this it passes the model to this method to see what to call the condition. If the condition type doesnt want to create a condition on
@@ -39,16 +43,29 @@ def condition_names_for_column
end
end
- def initialize(klass, column_obj = nil, column_type = nil, column_sql = nil)
+ def initialize(klass, options = {})
self.klass = klass
-
- if column_obj
- self.column = column_obj.class < ::ActiveRecord::ConnectionAdapters::Column ? column_obj : klass.columns_hash[column_obj.to_s]
- type = (!self.class.value_type.blank? && self.class.value_type.to_s) || (!column_type.blank? && column_type.to_s) || column.sql_type
- self.column_for_type_cast = column.class.new(column.name, column.default.to_s, type, column.null)
- self.column_sql = column_sql || "#{klass.connection.quote_table_name(klass.table_name)}.#{klass.connection.quote_column_name(column.name)}"
+ self.table_name = options[:table_name] || klass.table_name
+
+ if options[:column]
+ self.column = options[:column].class < ::ActiveRecord::ConnectionAdapters::Column ? options[:column] : klass.columns_hash[options[:column].to_s]
+
+ if options[:column_for_type_cast]
+ self.column_for_type_cast = options[:column_for_type_cast]
+ else
+ type = (!self.class.value_type.blank? && self.class.value_type.to_s) || (!options[:column_type].blank? && options[:column_type].to_s) || column.sql_type
+ self.column_for_type_cast = column.class.new(column.name, column.default.to_s, type, column.null)
+ end
+
+ self.column_sql_format = options[:column_sql_format] || "{table}.{column}"
end
end
+
+ # Substitutes string vars with table and column name. Allows us to switch the column and table on the fly and have the condition update appropriately.
+ # The table name could be variable depending on the condition. Take STI and more than one child model is used in the condition, the first gets the parent table name, the rest get aliases.
+ def column_sql
+ column_sql_format.gsub("{table}", quoted_table_name).gsub("{column}", quoted_column_name)
+ end
# Allows nils to be meaninful values
def explicitly_set_value=(value)
@@ -60,12 +77,16 @@ def explicitly_set_value?
@explicitly_set_value == true
end
+ def options
+ {:table_name => table_name, :column => column, :column_for_type_cast => column_for_type_cast, :column_sql_format => column_sql_format}
+ end
+
# You should refrain from overwriting this method, it performs various tasks before callign your to_conditions method, allowing you to keep to_conditions simple.
def sanitize(alt_value = nil) # :nodoc:
return if value_is_meaningless?
v = alt_value || value
if v.is_a?(Array) && !self.class.handle_array_value?
- merge_conditions(*v.collect { |i| sanitize(i) })
+ merge_conditions(*v.collect { |i| sanitize(i) } << {:any => self.class.join_arrays_with_or?})
else
v = v.utc if column && v.respond_to?(:utc) && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
to_conditions(v)
@@ -107,12 +128,16 @@ def quote_column_name(column_name)
klass.connection.quote_column_name(column_name)
end
+ def quoted_column_name
+ quote_column_name(column.name)
+ end
+
def quote_table_name(table_name)
klass.connection.quote_table_name(table_name)
end
def quoted_table_name
- quote_table_name(klass.table_name)
+ quote_table_name(table_name)
end
def type_cast_value(v)
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/begins_with.rb
@@ -1,6 +1,8 @@
module Searchgasm
module Condition
class BeginsWith < Base
+ self.join_arrays_with_or = true
+
class << self
def condition_names_for_column
super + ["bw", "sw", "starts_with", "start"]
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/child_of.rb
@@ -1,6 +1,6 @@
module Searchgasm
module Condition
- class ChildOf < Tree
+ class ChildOf < Tree
def to_conditions(value)
parent_association = klass.reflect_on_association(:parent)
foreign_key_name = (parent_association && parent_association.options[:foreign_key]) || "parent_id"
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/descendant_of.rb
@@ -1,6 +1,6 @@
module Searchgasm
module Condition
- class DescendantOf < Tree
+ class DescendantOf < Tree
def to_conditions(value)
# Wish I knew how to do this in SQL
root = (value.is_a?(klass) ? value : klass.find(value)) rescue return
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/ends_with.rb
@@ -1,6 +1,8 @@
module Searchgasm
module Condition
class EndsWith < Base
+ self.join_arrays_with_or = true
+
class << self
def condition_names_for_column
super + ["ew", "ends", "end"]
View
4 vendor/plugins/searchgasm/lib/searchgasm/condition/inclusive_descendant_of.rb
@@ -1,8 +1,8 @@
module Searchgasm
module Condition
- class InclusiveDescendantOf < Tree
+ class InclusiveDescendantOf < Tree
def to_conditions(value)
- condition = DescendantOf.new(klass, column)
+ condition = DescendantOf.new(klass, options)
condition.value = value
merge_conditions(["#{quoted_table_name}.#{quote_column_name(klass.primary_key)} = ?", (value.is_a?(klass) ? value.send(klass.primary_key) : value)], condition.sanitize, :any => true)
end
View
3  vendor/plugins/searchgasm/lib/searchgasm/condition/keywords.rb
@@ -1,6 +1,9 @@
module Searchgasm
module Condition
class Keywords < Base
+ # Because be default it joins with AND, so padding an array just gives you more options. Joining with and is no different than combining all of the words.
+ self.join_arrays_with_or = true
+
BLACKLISTED_WORDS = ('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"] # from ranks.nl
class << self
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/not_begin_with.rb
@@ -8,7 +8,7 @@ def condition_names_for_column
end
def to_conditions(value)
- begin_with = BeginWith.new
+ begin_with = BeginWith.new(klass, options)
begin_with.value = value
conditions = being_with.to_conditions
return conditions if conditions.blank?
View
17 vendor/plugins/searchgasm/lib/searchgasm/condition/not_blank.rb
@@ -0,0 +1,17 @@
+module Searchgasm
+ module Condition
+ class NotBlank < Base
+ class << self
+ def condition_names_for_column
+ super + ["is_not_blank"]
+ end
+ end
+
+ def to_conditions(value)
+ blank = Blank.new(klass, options)
+ blank.value = !value
+ blank.to_conditions
+ end
+ end
+ end
+end
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/not_end_with.rb
@@ -8,7 +8,7 @@ def condition_names_for_column
end
def to_conditions(value)
- ends_with = EndsWith.new
+ ends_with = EndsWith.new(klass, options)
ends_with.value = value
conditions = ends_with.to_conditions
return conditions if conditions.blank?
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/not_equal.rb
@@ -12,7 +12,7 @@ def condition_names_for_column
def to_conditions(value)
# Delegate to equals and then change
- condition = Equals.new(klass, column)
+ condition = Equals.new(klass, options)
condition.value = value
conditions_array = condition.sanitize
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/not_have_keywords.rb
@@ -8,7 +8,7 @@ def condition_names_for_column
end
def to_conditions(value)
- keywords = Keywords.new
+ keywords = Keywords.new(klass, options)
keywords.value = value
conditions = keywords.to_conditions
return conditions if conditions.blank?
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/not_like.rb
@@ -8,7 +8,7 @@ def condition_names_for_column
end
def to_conditions(value)
- like = Like.new
+ like = Like.new(klass, options)
like.value = value
conditions = like.to_conditions
return conditions if conditions.blank?
View
17 vendor/plugins/searchgasm/lib/searchgasm/condition/not_nil.rb
@@ -0,0 +1,17 @@
+module Searchgasm
+ module Condition
+ class NotNil < Base
+ class << self
+ def condition_names_for_column
+ super + ["is_not_nil", "is_not_null", "not_null"]
+ end
+ end
+
+ def to_conditions(value)
+ is_nil = Nil.new(klass, options)
+ is_nil.value = !value
+ is_nil.to_conditions
+ end
+ end
+ end
+end
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/sibling_of.rb
@@ -5,7 +5,7 @@ def to_conditions(value)
parent_association = klass.reflect_on_association(:parent)
foreign_key_name = (parent_association && parent_association.options[:foreign_key]) || "parent_id"
parent_id = (value.is_a?(klass) ? value : klass.find(value)).send(foreign_key_name)
- condition = ChildOf.new(klass, column)
+ condition = ChildOf.new(klass, options)
condition.value = parent_id
merge_conditions(["#{quoted_table_name}.#{quote_column_name(klass.primary_key)} != ?", (value.is_a?(klass) ? value.send(klass.primary_key) : value)], condition.sanitize)
end
View
2  vendor/plugins/searchgasm/lib/searchgasm/condition/tree.rb
@@ -1,6 +1,8 @@
module Searchgasm
module Condition
class Tree < Base # :nodoc:
+ self.join_arrays_with_or = true
+
class << self
def condition_names_for_column
[]
View
16 vendor/plugins/searchgasm/lib/searchgasm/conditions/base.rb
@@ -179,7 +179,7 @@ def auto_joins
associations.each do |name, association|
next if association.conditions.blank?
association_joins = association.auto_joins
- j << (association_joins.blank? ? association.relationship_name.to_sym : {association.relationship_name.to_sym => association_joins})
+ j << (association_joins.blank? ? name : {name => association_joins})
end
j.blank? ? nil : (j.size == 1 ? j.first : j)
end
@@ -233,7 +233,7 @@ def conditions
if object.class < Searchgasm::Conditions::Base
relationship_conditions = object.conditions
next if relationship_conditions.blank?
- conditions_hash[object.relationship_name.to_sym] = relationship_conditions
+ conditions_hash[name] = relationship_conditions
else
next if object.value_is_meaningless?
conditions_hash[name] = object.value
@@ -367,14 +367,14 @@ def setup_condition(name)
column_type = modifier_klasses.first.return_type
# Build the column sql
- column_sql = "#{klass.connection.quote_table_name(klass.table_name)}.#{klass.connection.quote_column_name(column_detail[:column].name)}"
+ column_sql = "{table}.{column}"
modifier_klasses.each do |modifier_klass|
next unless klass.connection.respond_to?(modifier_klass.adapter_method_name)
column_sql = klass.connection.send(modifier_klass.adapter_method_name, column_sql)
end
end
- add_condition!(condition_klass, method_name, column_detail[:column], column_type, column_sql)
+ add_condition!(condition_klass, method_name, :column => column_detail[:column], :column_type => column_type, :column_sql_format => column_sql)
([column_detail[:column].name] + column_detail[:aliases]).each do |column_name|
condition_klass.condition_names_for_column.each do |condition_name|
@@ -393,13 +393,15 @@ def setup_condition(name)
false
end
- def add_condition!(condition, name, column = nil, column_type = nil, column_sql = nil)
+ def add_condition!(condition, name, options = {})
self.class.condition_names << name
+ options[:column] = options[:column].name if options[:column].class < ::ActiveRecord::ConnectionAdapters::Column
self.class.class_eval <<-"end_eval", __FILE__, __LINE__
def #{name}_object
if objects[:#{name}].nil?
- objects[:#{name}] = #{condition.name}.new(klass, #{column.blank? ? "nil" : "klass.columns_hash['#{column.name}']"}, #{column_type.blank? ? "nil" : "\"#{column_type}\""}, #{column_sql.blank? ? "nil" : "\"#{column_sql.gsub('"', '\"')}\""})
+ options = {}
+ objects[:#{name}] = #{condition.name}.new(klass, #{options.inspect})
end
objects[:#{name}]
end
@@ -465,7 +467,7 @@ def objects
end
def reset_objects!
- objects.each { |name, object| object.class < ::Searchgasm::Conditions::Base ? eval("@#{object.relationship_name} = nil") : eval("@#{name} = nil") }
+ objects.each { |name, object| eval("@#{name} = nil") }
objects.clear
end
View
2  vendor/plugins/searchgasm/lib/searchgasm/conditions/protection.rb
@@ -23,7 +23,7 @@ def conditions_with_protection=(conditions)
end
def protect=(value)
- associations.each { |association| association.protect = value }
+ associations.each { |name, obj| obj.protect = value }
@protect = value
end
View
167 vendor/plugins/searchgasm/lib/searchgasm/config.rb
@@ -1,14 +1,16 @@
module Searchgasm
# = Config
- # Adds default configuration for all of searchgasm. Just make sure you set your config before you use Searchgasm.
- # For rails the best place to do this is in config/initializers. Create a file in there called searchgasm.rb with the following content:
+ # Adds default configuration for all of searchgasm. For rails the best place to do this is in config/initializers. Create a file in there called searchgasm.rb with the following content:
#
# === Example
#
# # config/iniitializers/searchgasm.rb
# Searchgasm::Config.configure do |config|
- # config.you_option_here = your_value # see methods below
+ # config.search.per_page = 25
+ # config.helpers.order_by_link_asc_indicator = "My indicator"
# end
+ #
+ # For a list of all configuration options see Searchgasm::Config::Search and Searchgasm::Config::Helpers
class Config
class << self
# Convenience method for setting configuration
@@ -17,163 +19,12 @@ def configure
yield self
end
- def asc_indicator # :nodoc:
- @asc_indicator ||= "&nbsp;&#9650;"
- end
-
- # The indicator that is used when the sort of a column is ascending
- #
- # * <tt>Default:</tt> &nbsp;&#9650;
- # * <tt>Accepts:</tt> String or a Proc.
- #
- # === Examples
- #
- # config.asc_indicator = "(ASC)"
- # config.asc_indicator = Proc.new { |template| template.image_tag("asc.jpg") }
- def asc_indicator=(value)
- @asc_indicator = value
- end
-
- def desc_indicator # :nodoc:
- @desc_indicator ||= "&nbsp;&#9660;"
- end
-
- # See asc_indicator=
- def desc_indicator=(value)
- @desc_indicator = value
- end
-
- def hidden_fields # :nodoc:
- @hidden_fields ||= (Search::Base::SPECIAL_FIND_OPTIONS - [:page, :priority_order])
- end
-
- # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::Form for more info.
- #
- # * <tt>Default:</tt> [:order_by, :order_as, :per_page]
- # * <tt>Accepts:</tt> Array, nil, false
- def hidden_fields=(value)
- @hidden_fields = value
- end
-
- def page_links_first # :nodoc:
- @page_links_first
- end
-
- # The default for the :first option for the page_links helper.
- #
- # * <tt>Default:</tt> nil
- # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
- def page_links_first=(value)
- @page_links_first = value
- end
-
- def page_links_last # :nodoc:
- @page_links_last
- end
-
- # The default for the :last option for the page_links helper.
- #
- # * <tt>Default:</tt> nil
- # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
- def page_links_last=(value)
- @page_links_last = value
- end
-
- def page_links_inner_spread # :nodoc:
- @page_links_inner_spread ||= 3
- end
-
- # The default for the :inner_spread option for the page_links helper.
- #
- # * <tt>Default:</tt> 3
- # * <tt>Accepts:</tt> Any integer >= 1, set to nil to show all pages
- def page_links_inner_spread=(value)
- @page_links_inner_spread = value
- end
-
- def page_links_outer_spread # :nodoc:
- @page_links_outer_spread ||= 1
- end
-
- # The default for the :outer_spread option for the page_links helper.
- #
- # * <tt>Default:</tt> 2
- # * <tt>Accepts:</tt> Any integer >= 1, set to nil to display, 0 to only show the "..." separator
- def page_links_outer_spread=(value)
- @page_links_outer_spread = value
- end
-
- def page_links_next # :nodoc:
- @page_links_next ||= "Next >"
- end
-
- # The default for the :next option for the page_links helper.
- #
- # * <tt>Default:</tt> "Next >"
- # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
- def page_links_next=(value)
- @page_links_next = value
- end
-
- def page_links_prev # :nodoc:
- @page_links_prev ||= "< Prev"
- end
-
- # The default for the :prev option for the page_links helper.
- #
- # * <tt>Default:</tt> "< Prev"
- # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
- def page_links_prev=(value)
- @page_links_prev = value
- end
-
- def per_page # :nodoc:
- @per_page ||= per_page_choices[1]
- end
-
- # The default for per page. This is only applicaple for protected searches. Meaning you start the search with new_search or new_conditions.
- # The reason for this not to disturb regular queries such as Whatever.find(:all). You would not expect that to be limited.
- #
- # * <tt>Default:</tt> The 3rd option in your per_page_choices, default of 50
- # * <tt>Accepts:</tt> Any value in your per_page choices, nil or a blank string means "show all"
- def per_page=(value)
- @per_page = value
- end
-
- def per_page_choices # :nodoc:
- @per_page_choices ||= [10, 25, 50, 100, 150, 200, nil]
- end
-
- # The choices used in the per_page helper
- #
- # * <tt>Default:</tt> [10, 25, 50, 100, 150, 200, nil]
- # * <tt>Accepts:</tt> Array
- #
- # nil means "Show all"
- def per_page_choices=(value)
- @per_page_choices = value
- end
-
- def remove_duplicates # :nodoc:
- return @remove_duplicates if @set_remove_duplicates
- @remove_duplicates ||= true
- end
-
- def remove_duplicates? # :nodoc:
- remove_duplicates == true
+ def search # :nodoc:
+ Search
end
- # If you are using ActiveRecord < 2.2.0 then ActiveRecord does not remove duplicates when using the :joins option, when it should. To fix this problem searchgasm does this for you. Searchgasm tries to act
- # just like ActiveRecord, but in this instance it doesn't make sense.
- #
- # As a result, Searchgasm removes all duplicates results in *ALL* search / calculation queries. It does this by forcing the DISTINCT or GROUP BY operation in your SQL. Which might come as a surprise to you
- # since it is not the "norm". If you don't want searchgasm to do this, set this to false.
- #
- # * <tt>Default:</tt> true
- # * <tt>Accepts:</tt> Boolean
- def remove_duplicates=(value)
- @set_remove_duplicates = true
- @remove_duplicates = value
+ def helpers # :nodoc:
+ Helpers
end
end
end
View
279 vendor/plugins/searchgasm/lib/searchgasm/config/helpers.rb
@@ -0,0 +1,279 @@
+module Searchgasm
+ class Config
+ # = Helpers Configuration
+ # Provide configuration for searchgasm's rails helpers
+ #
+ # === Example
+ # Searchgasm::Config.configure do |config|
+ # config.helpers.order_by_link_asc_indicator = "ASC"
+ # end
+ class Helpers
+ class << self
+ # Which hidden fields to automatically include when creating a form with a Searchgasm object. See Searchgasm::Helpers::Form for more info.
+ #
+ # * <tt>Default:</tt> [:order_by, :order_as, :per_page]
+ # * <tt>Accepts:</tt> Array, nil, false
+ def hidden_fields
+ @hidden_fields ||= (Searchgasm::Search::Base::SPECIAL_FIND_OPTIONS - [:page, :priority_order])
+ end
+ attr_writer :hidden_fields
+
+ # The class name for used in the order_as_link helper
+ #
+ # * <tt>Default:</tt> "order_as"
+ # * <tt>Accepts:</tt> String
+ def order_as_link_class_name
+ @order_as_link_class_name ||= "order_as"
+ end
+ attr_writer :order_as_link_class_name
+
+ # The class name for used in the order_as_select helper
+ #
+ # * <tt>Default:</tt> "order_as"
+ # * <tt>Accepts:</tt> String
+ def order_as_select_class_name
+ @order_as_select_class_name ||= "order_as"
+ end
+ attr_writer :order_as_select_class_name
+
+ # The indicator that is used when the sort of a column is ascending
+ #
+ # * <tt>Default:</tt> &nbsp;&#9650;
+ # * <tt>Accepts:</tt> String or a Proc.
+ #
+ # === Examples
+ #
+ # config.asc_indicator = "(ASC)"
+ # config.asc_indicator = Proc.new { |template| template.image_tag("asc.jpg") }
+ def order_by_link_asc_indicator
+ @order_by_link_asc_indicator ||= "&nbsp;&#9650;"
+ end
+ attr_writer :order_by_link_asc_indicator
+
+ # The class name for used in the order_by_link helper
+ #
+ # * <tt>Default:</tt> "order_by"
+ # * <tt>Accepts:</tt> String
+ def order_by_link_class_name
+ @order_by_link_class_name ||= "order_by"
+ end
+ attr_writer :order_by_link_class_name
+
+ # See order_by_link_asc_indicator=
+ def order_by_link_desc_indicator
+ @order_by_link_desc_indicator ||= "&nbsp;&#9660;"
+ end
+ attr_writer :order_by_link_desc_indicator
+
+ # The class name used in order_by_links for the link that it is currently ordering by
+ #
+ # * <tt>Default:</tt> "# The class name for used in the page_link helper
+ #
+ # * <tt>Default:</tt> "page"
+ # * <tt>Accepts:</tt> String
+ def order_by_links_ordering_by_class_name
+ @order_by_links_ordering_by_class_name ||= "ordering_by"
+ end
+ attr_writer :order_by_links_ordering_by_class_name
+
+ # The class name for used in the order_by_select helper
+ #
+ # * <tt>Default:</tt> "order_by"
+ # * <tt>Accepts:</tt> String
+ def order_by_select_class_name
+ @order_by_select_class_name ||= "order_by"
+ end
+ attr_writer :order_by_select_class_name
+
+ # The class name for used in the page_link helper
+ #
+ # * <tt>Default:</tt> "page"
+ # * <tt>Accepts:</tt> String
+ def page_link_class_name
+ @page_link_class_name ||= "page"
+ end
+ attr_writer :page_link_class_name
+
+ # The choices used in the per_page_links helper. Works just like per_page_select_choices.
+ def per_page_links_choices
+ @per_page_links_choices ||= per_page_select_choices
+ end
+ attr_writer :per_page_links_choices
+
+ # The class that the current page link gets.
+ #
+ # * <tt>Default:</tt> "current_page"
+ # * <tt>Accepts:</tt> String, set to nil to disable
+ def page_links_current_page_class_name
+ @page_links_current_page_class_name ||= "current_page"
+ end
+ attr_writer :page_links_current_page_class_name
+
+ # The class that disabled page links get. Including the current page, prev page, next page, first page, and last page.
+ #
+ # * <tt>Default:</tt> "disabled_page"
+ # * <tt>Accepts:</tt> String, set to nil to disable
+ def page_links_disabled_class_name
+ @page_links_disabled_class_name ||= "disabled_page"
+ end
+ attr_writer :page_links_disabled_class_name
+
+ # The default for the :first option for the page_links helper.
+ #
+ # * <tt>Default:</tt> nil
+ # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
+ def page_links_first
+ @page_links_first
+ end
+ attr_writer :page_links_first
+
+ # The default for the :inner_spread option for the page_links helper.
+ #
+ # * <tt>Default:</tt> 3
+ # * <tt>Accepts:</tt> Any integer >= 1, set to nil to show all pages
+ def page_links_inner_spread
+ @page_links_inner_spread ||= 3
+ end
+ attr_writer :page_links_inner_spread
+
+ # The class for the first page link
+ #
+ # * <tt>Default:</tt> "first_page"
+ # * <tt>Accepts:</tt> String, nil to disable
+ def page_links_first_page_class_name
+ @page_links_first_page_class_name ||= "first_page"
+ end
+ attr_writer :page_links_first_page_class_name
+
+ # The default for the :last option for the page_links helper.
+ #
+ # * <tt>Default:</tt> nil
+ # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
+ def page_links_last
+ @page_links_last
+ end
+ attr_writer :page_links_last
+
+ # The class for the last page link
+ #
+ # * <tt>Default:</tt> "last_page"
+ # * <tt>Accepts:</tt> String, nil to disable
+ def page_links_last_page_class_name
+ @page_links_last_page_class_name ||= "last_page"
+ end
+ attr_writer :page_links_last_page_class_name
+
+ # The default for the :next option for the page_links helper.
+ #
+ # * <tt>Default:</tt> "Next >"
+ # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
+ def page_links_next
+ @page_links_next ||= "Next &gt;"
+ end
+ attr_writer :page_links_next
+
+ # The class for the next page link
+ #
+ # * <tt>Default:</tt> "next_page"
+ # * <tt>Accepts:</tt> String, nil to disable
+ def page_links_next_page_class_name
+ @page_links_next_page_class_name ||= "next_page"
+ end
+ attr_writer :page_links_next_page_class_name
+
+ # The default for the :outer_spread option for the page_links helper.
+ #
+ # * <tt>Default:</tt> 2
+ # * <tt>Accepts:</tt> Any integer >= 1, set to nil to display, 0 to only show the "..." separator
+ def page_links_outer_spread
+ @page_links_outer_spread ||= 1
+ end
+ attr_writer :page_links_outer_spread
+
+ # The class for the previous page link
+ #
+ # * <tt>Default:</tt> "prev_page"
+ # * <tt>Accepts:</tt> String, nil to disable
+ def page_links_prev_page_class_name
+ @page_links_prev_page_class_name ||= "prev_page"
+ end
+ attr_writer :page_links_prev_page_class_name
+
+ # The default for the :prev option for the page_links helper.
+ #
+ # * <tt>Default:</tt> "< Prev"
+ # * <tt>Accepts:</tt> Anything you want, text, html, etc. nil to disable
+ def page_links_prev
+ @page_links_prev ||= "&lt; Prev"
+ end
+ attr_writer :page_links_prev
+
+ # The class name for used in the page_seect helper
+ #
+ # * <tt>Default:</tt> "page"
+ # * <tt>Accepts:</tt> String
+ def page_select_class_name
+ @page_select_class_name ||= "page"
+ end
+ attr_writer :page_select_class_name
+
+ # The class name for used in the per_page_link helper
+ #
+ # * <tt>Default:</tt> "per_page"
+ # * <tt>Accepts:</tt> String
+ def per_page_link_class_name
+ @per_page_link_class_name ||= "per_page"
+ end
+ attr_writer :per_page_link_class_name
+
+ # The choices used in the per_page_select helper
+ #
+ # * <tt>Default:</tt> [["10 per page", 10], ["25 per page", 25], ["50 per page", 50], ["100 per page", 100], ["150 per page", 150], ["200 per page", 200], ["Show all", nil]]
+ # * <tt>Accepts:</tt> Array
+ def per_page_select_choices
+ return @per_page_select_choices if @per_page_select_choices
+ @per_page_select_choices = []
+ [10, 25, 50, 100, 150, 200].each { |choice| @per_page_select_choices << ["#{choice} per page", choice] }
+ @per_page_select_choices << ["Show all", nil]
+ end
+ attr_writer :per_page_select_choices
+
+ # The class name for used in the per_page_select helper
+ #
+ # * <tt>Default:</tt> "per_page"
+ # * <tt>Accepts:</tt> String
+ def per_page_select_class_name
+ @per_page_select_class_name ||= "per_page"
+ end
+ attr_writer :per_page_select_class_name
+
+ # The default value for the :activate_text option for priority_order_by_link
+ #
+ # * <tt>Default:</tt> "Show %s first"
+ # * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
+ def priority_order_by_link_activate_text
+ @priority_order_by_link_activate_text ||= "Show %s first"
+ end
+ attr_writer :priority_order_by_link_activate_text
+
+ # The class name for used in the priority_order_by_link helper
+ #
+ # * <tt>Default:</tt> "priority_order_by"
+ # * <tt>Accepts:</tt> String
+ def priority_order_by_link_class_name
+ @priority_order_by_link_class_name ||= "priority_order_by"
+ end
+ attr_writer :priority_order_by_link_class_name
+
+ # The default value for the :deactivate_text option for priority_order_by_link
+ #
+ # * <tt>Default:</tt> "Dont' show %s first"
+ # * <tt>Accepts:</tt> String with substitutions, using rubys % method for strings
+ def priority_order_by_link_deactivate_text
+ @priority_order_by_link_deactivate_text ||= "Don't show %s first"
+ end
+ attr_writer :priority_order_by_link_deactivate_text
+ end
+ end
+ end
+end
View
53 vendor/plugins/searchgasm/lib/searchgasm/config/search.rb
@@ -0,0 +1,53 @@
+module Searchgasm
+ class Config
+ # = Search Configuration
+ # Provides configuration for searchgasm
+ #
+ # === Example
+ # Searchgasm::Config.configure do |config|
+ # config.search.per_page = 50
+ # end
+ class Search
+ class << self
+ # The default for per page. This is only applicaple for protected searches. Meaning you start the search with new_search or new_conditions.
+ # The reason for this not to disturb regular queries such as Whatever.find(:all). You would not expect that to be limited.
+ #
+ # * <tt>Default:</tt> The 2nd option in your per_page_choices, default of 25
+ # * <tt>Accepts:</tt> Any value in your per_page choices, nil or a blank string means "show all"
+ def per_page
+ return @per_page if @set_per_page
+ per_page = Helpers.per_page_select_choices[1]
+ per_page = per_page.last if per_page.is_a?(Array)
+ @per_page = per_page
+ end
+
+ def per_page=(value)
+ @set_per_page = true
+ @per_page = value
+ end
+
+ # If you are using ActiveRecord < 2.2.0 then ActiveRecord does not remove duplicates when using the :joins option, when it should. To fix this problem searchgasm does this for you. Searchgasm tries to act
+ # just like ActiveRecord, but in this instance it doesn't make sense.
+ #
+ # As a result, Searchgasm removes all duplicates results in *ALL* search / calculation queries. It does this by forcing the DISTINCT or GROUP BY operation in your SQL. Which might come as a surprise to you
+ # since it is not the "norm". If you don't want searchgasm to do this, set this to false.
+ #
+ # * <tt>Default:</tt> true
+ # * <tt>Accepts:</tt> Boolean
+ def remove_duplicates
+ return @remove_duplicates if @set_remove_duplicates
+ @remove_duplicates ||= true
+ end
+
+ def remove_duplicates? # :nodoc:
+ remove_duplicates == true
+ end
+
+ def remove_duplicates=(value) # :nodoc:
+ @set_remove_duplicates = true
+ @remove_duplicates = value
+ end
+ end
+ end
+ end
+end
View
48 vendor/plugins/searchgasm/lib/searchgasm/helpers/control_types/link.rb
@@ -78,10 +78,10 @@ module Link
# * <tt>:html</tt> -- html arrtributes for the <a> tag.
#
# === Advanced Options
- # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base level in params such as params[:page], params[:per_page], etc, then set this to nil.
# * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
# * <tt>:params</tt> -- default: nil, Additional params to add to the url, must be a hash
- # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get include. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
+ # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get included. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
# * <tt>:search_params</tt> -- default: nil, Additional search params to add to the url, must be a hash. Adds the options into the :params_scope.
# * <tt>:exclude_search_params</tt> -- default: nil, Same as :exclude_params but for the :search_params.
def order_by_link(order_by, options = {})
@@ -97,7 +97,7 @@ def order_by_link(order_by, options = {})
html
end
- # Creates a link for ascending or descending data, pretty self e
+ # Creates a link for ascending or descending data.
#
# === Example uses
#
@@ -110,10 +110,10 @@ def order_by_link(order_by, options = {})
# * <tt>:html</tt> -- html arrtributes for the <a> tag.
#
# === Advanced Options
- # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base level in params such as params[:page], params[:per_page], etc, then set this to nil.
# * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
# * <tt>:params</tt> -- default: nil, Additional params to add to the url, must be a hash
- # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get include. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
+ # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get included. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
# * <tt>:search_params</tt> -- default: nil, Additional search params to add to the url, must be a hash. Adds the options into the :params_scope.
# * <tt>:exclude_search_params</tt> -- default: nil, Same as :exclude_params but for the :search_params.
def order_as_link(order_as, options = {})
@@ -151,10 +151,10 @@ def order_as_link(order_as, options = {})
# * <tt>:html</tt> -- html arrtributes for the <a> tag.
#
# === Advanced Options
- # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base level in params such as params[:page], params[:per_page], etc, then set this to nil.
# * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
# * <tt>:params</tt> -- default: nil, Additional params to add to the url, must be a hash
- # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get include. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
+ # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get included. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
# * <tt>:search_params</tt> -- default: nil, Additional search params to add to the url, must be a hash. Adds the options into the :params_scope.
# * <tt>:exclude_search_params</tt> -- default: nil, Same as :exclude_params but for the :search_params.
def priority_order_by_link(priority_order_by, priority_order_as, options = {})
@@ -181,14 +181,13 @@ def priority_order_by_link(priority_order_by, priority_order_as, options = {})
# As you can see above, passing nil means "show all" and the text will automatically revert to "show all"
#
# === Options
- # * <tt>:text</tt> -- default: column_name.to_s.humanize, text for the link
# * <tt>:html</tt> -- html arrtributes for the <a> tag.
#
# === Advanced Options
- # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base level in params such as params[:page], params[:per_page], etc, then set this to nil.
# * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
# * <tt>:params</tt> -- default: nil, Additional params to add to the url, must be a hash
- # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get include. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
+ # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get included. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
# * <tt>:search_params</tt> -- default: nil, Additional search params to add to the url, must be a hash. Adds the options into the :params_scope.
# * <tt>:exclude_search_params</tt> -- default: nil, Same as :exclude_params but for the :search_params.
def per_page_link(per_page, options = {})
@@ -217,10 +216,10 @@ def per_page_link(per_page, options = {})
# * <tt>:html</tt> -- html arrtributes for the <a> tag.
#
# === Advanced Options
- # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base leve in params such as params[:page], params[:per_page], etc, then set this to nil.
+ # * <tt>:params_scope</tt> -- default: :search, this is the scope in which your search params will be preserved (params[:search]). If you don't want a scope and want your options to be at base level in params such as params[:page], params[:per_page], etc, then set this to nil.
# * <tt>:search_obj</tt> -- default: @#{params_scope}, this is your search object, everything revolves around this. It will try to infer the name from your params_scope. If your params_scope is :search it will try to get @search, etc. If it can not be inferred by this, you need to pass the object itself.
# * <tt>:params</tt> -- default: nil, Additional params to add to the url, must be a hash
- # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get include. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
+ # * <tt>:exclude_params</tt> -- default: nil, params you want to exclude. This is nifty because it does a "deep delete". So you can pass {:param1 => {:param2 => :param3}} and it will make sure param3 does not get included. param1 and param2 will not be touched. This also accepts an array or just a symbol or string.
# * <tt>:search_params</tt> -- default: nil, Additional search params to add to the url, must be a hash. Adds the options into the :params_scope.
# * <tt>:exclude_search_params</tt> -- default: nil, Same as :exclude_params but for the :search_params.
def page_link(page, options = {})
@@ -238,29 +237,32 @@ def page_link(page, options = {})
private
def add_order_by_link_defaults!(order_by, options = {})
- add_searchgasm_control_defaults!(:order_by, options)
+ add_searchgasm_control_defaults!(options)
+ searchgasm_add_class!(options[:html], Config.helpers.order_by_link_class_name)
ordering_by_this = searchgasm_ordering_by?(order_by, options)
searchgasm_add_class!(options[:html], "ordering") if ordering_by_this
options[:text] ||= determine_order_by_text(order_by)
- options[:asc_indicator] ||= Config.asc_indicator
- options[:desc_indicator] ||= Config.desc_indicator
+ options[:asc_indicator] ||= Config.helpers.order_by_link_asc_indicator
+ options[:desc_indicator] ||= Config.helpers.order_by_link_desc_indicator
options[:text] += options[:search_obj].desc? ? options[:desc_indicator] : options[:asc_indicator] if ordering_by_this
options[:url] = searchgasm_params(options.merge(:search_params => {:order_by => order_by}))
options
end
def add_order_as_link_defaults!(order_as, options = {})
- add_searchgasm_control_defaults!(:order_as, options)
+ add_searchgasm_control_defaults!(options)
+ searchgasm_add_class!(options[:html], Config.helpers.order_as_link_class_name)
options[:text] ||= order_as.to_s
options[:url] = searchgasm_params(options.merge(:search_params => {:order_as => order_as}))
options
end
def add_priority_order_by_link_defaults!(priority_order_by, priority_order_as, options = {})
- add_searchgasm_control_defaults!(:priority_order_by, options)
+ add_searchgasm_control_defaults!(options)
+ searchgasm_add_class!(options[:html], Config.helpers.priority_order_by_link_class_name)
options[:column_name] ||= determine_order_by_text(priority_order_by).downcase
- options[:activate_text] ||= "Show #{options[:column_name]} first"
- options[:deactivate_text] ||= "Don't show #{options[:column_name]} first"
+ options[:activate_text] ||= Config.helpers.priority_order_by_link_activate_text % options[:column_name]
+ options[:deactivate_text] ||= Config.helpers.priority_order_by_link_deactivate_text % options[:column_name]
active = deep_stringify(options[:search_obj].priority_order_by) == deep_stringify(priority_order_by) && options[:search_obj].priority_order_as == priority_order_as
options[:text] ||= active ? options[:deactivate_text] : options[:activate_text]
if active
@@ -273,14 +275,16 @@ def add_priority_order_by_link_defaults!(priority_order_by, priority_order_as, o
end
def add_per_page_link_defaults!(per_page, options = {})
- add_searchgasm_control_defaults!(:per_page, options)
- options[:text] ||= per_page.blank? ? "Show all" : "#{per_page} per page"
+ add_searchgasm_control_defaults!(options)
+ searchgasm_add_class!(options[:html], Config.helpers.per_page_link_class_name)
+ options[:text] ||= per_page.to_s
options[:url] = searchgasm_params(options.merge(:search_params => {:per_page => per_page}))
options
end
def add_page_link_defaults!(page, options = {})
- add_searchgasm_control_defaults!(:page, options)
+ add_searchgasm_control_defaults!(options)
+ searchgasm_add_class!(options[:html], Config.helpers.page_link_class_name)
options[:text] ||= page.to_s
options[:url] = searchgasm_params(options.merge(:search_params => {:page => page}))
options
View
89 vendor/plugins/searchgasm/lib/searchgasm/helpers/control_types/links.rb
@@ -16,10 +16,15 @@ module Links
# * <tt>:choices</tt> -- default: the models column names, the choices to loop through when calling order_by_link
def order_by_links(options = {})
add_order_by_links_defaults!(options)
- link_options = options.deep_dup
- link_options.delete(:choices)
+ links_options = options.deep_dup
+ links_options.delete(:choices)
html = ""
- options[:choices].each { |choice| html += order_by_link(choice, link_options.deep_dup) }
+ options[:choices].each do |choice|
+ link_options = links_option.deep_dup
+ text, value = option_text_and_value(choice)
+ link_options[:text] ||= text
+ html += order_by_link(value, link_options)
+ end
html
end
@@ -37,10 +42,15 @@ def order_by_links(options = {})
# * <tt>:choices</tt> -- default: ["asc", "desc"], the choices to loop through when calling order_as_link
def order_as_links(options = {})
add_order_as_links_defaults!(options)
- link_options = options.deep_dup
- link_options.delete(:choices)
+ links_options = options.deep_dup
+ links_options.delete(:choices)
html = ""
- options[:choices].each { |choice| html += order_as_link(choice, link_options.deep_dup) }
+ options[:choices].each do |choice|
+ link_options = links_option.deep_dup
+ text, value = option_text_and_value(choice)
+ link_options[:text] ||= text
+ html += order_as_link(value, link_options)
+ end
html
end
@@ -55,13 +65,19 @@ def order_as_links(options = {})
#
# Please look at per_page_link. All options there are applicable here and are passed onto each option.
#
- # * <tt>:choices</tt> -- default: [10, 25, 50, 100, 150, 200, nil], the choices to loop through when calling per_page_link.
+ # * <tt>:choices</tt> -- default: [["10 per page", 10], ["25 per page", 25], ["50 per page", 50], ["100 per page", 100], ["150 per page", 150], ["200 per page", 200], ["Show all", nil]]
def per_page_links(options = {})
add_per_page_links_defaults!(options)
- link_options = options.deep_dup
- link_options.delete(:choices)
+ links_options = options.deep_dup
+ links_options.delete(:choices)
html = ""
- options[:choices].each { |choice| html += per_page_link(choice, link_options.deep_dup) }
+ options[:choices].each do |choice|
+ link_options = links_options.deep_dup
+ text, value = option_text_and_value(choice)
+ link_options[:text] ||= text
+ searchgasm_add_class!(link_options[:html], Config.helpers.order_by_links_ordering_by_class_name) if link_options[:search_obj].per_page == value
+ html += per_page_link(value, link_options)
+ end
html
end
@@ -148,41 +164,51 @@ def page_links(options = {})
private
def add_order_by_links_defaults!(options)
- add_searchgasm_control_defaults!(:order_by, options)
+ add_searchgasm_control_defaults!(options)
options[:choices] ||= options[:search_obj].klass.column_names.map(&:humanize)
options
end
def add_order_as_links_defaults!(options)
- add_searchgasm_control_defaults!(:order_as, options)
+ add_searchgasm_control_defaults!(options)
options[:choices] = [:asc, :desc]
options
end
def add_per_page_links_defaults!(options)
- add_searchgasm_control_defaults!(:per_page, options)
- options[:choices] ||= Config.per_page_choices.dup
- if !options[:search_obj].per_page.blank? && !options[:choices].include?(options[:search_obj].per_page)
- options[:choices] << options[:search_obj].per_page
- has_nil = options[:choices].include?(nil)
- options[:choices].compact!
- options[:choices].sort!
- options[:choices] << nil if has_nil
+ add_searchgasm_control_defaults!(options)
+ options[:choices] ||= Config.helpers.per_page_links_choices.dup
+ if !options[:search_obj].per_page.blank? && !choices_include?(options[:choices], options[:search_obj].per_page)
+ options[:choices] << ["#{options[:search_obj].per_page} per page", options[:search_obj].per_page]
+ options[:choices].sort! do |a, b|
+ a_value = (a.is_a?(Array) ? a.last : a).to_i
+ return -1 if a_value == 0
+ b_value = (b.is_a?(Array) ? b.last : b).to_i
+ a_value <=> b_value
+ end
end
options
end
+ def choices_include?(choices, includes)
+ choices.each do |choice|
+ value = choice.is_a?(Array) ? choice.last : choice
+ return true if value == includes
+ end
+ false
+ end
+
def add_page_links_defaults!(options)
- add_searchgasm_control_defaults!(:page, options)
+ add_searchgasm_control_defaults!(options)
options[:first_page] ||= 1
options[:last_page] ||= options[:search_obj].page_count
options[:current_page] ||= options[:search_obj].page
- options[:inner_spread] = Config.page_links_inner_spread unless options.has_key?(:inner_spread)
- options[:outer_spread] = Config.page_links_outer_spread unless options.has_key?(:outer_spread)
- options[:prev] = Config.page_links_prev unless options.has_key?(:prev)
- options[:next] = Config.page_links_next unless options.has_key?(:next)
- options[:first] = Config.page_links_first unless options.has_key?(:first)
- options[:last] = Config.page_links_last unless options.has_key?(:last)
+ options[:inner_spread] = Config.helpers.page_links_inner_spread unless options.has_key?(:inner_spread)
+ options[:outer_spread] = Config.helpers.page_links_outer_spread unless options.has_key?(:outer_spread)
+ options[:prev] = Config.helpers.page_links_prev unless options.has_key?(:prev)
+ options[:next] = Config.helpers.page_links_next unless options.has_key?(:next)
+ options[:first] = Config.helpers.page_links_first unless options.has_key?(:first)
+ options[:last] = Config.helpers.page_links_last unless options.has_key?(:last)
options
end
@@ -193,14 +219,17 @@ def span_or_page_link(name, options, span)
when Fixnum
text = name
page = name
- searchgasm_add_class!(options[:html], "current_page") if span