searchify 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,9 +11,10 @@ module Searchify
11
11
  resource_class = params[:collection].classify.constantize
12
12
  search_term = params[:term]
13
13
  search_keyword = extract_search_key(resource_class)
14
+ search_strategy = params[:search_strategy] || :search_strategy
14
15
 
15
- collection = if resource_class.respond_to?(:search_strategy)
16
- resource_class.search_strategy(search_term, searchify_scopes)
16
+ collection = if resource_class.respond_to?(search_strategy)
17
+ resource_class.send(search_strategy, search_term, searchify_scopes)
17
18
  else
18
19
  columns = Searchify::Config.column_names & resource_class.column_names
19
20
 
@@ -5,7 +5,7 @@ module Searchify
5
5
 
6
6
  # searchify options
7
7
  collection = options.delete(:collection) || args.shift || extract_collection
8
- search_url = options.delete(:search_url) || extract_search_url(collection, options.delete(:scopes) || {})
8
+ search_url = options.delete(:search_url) || extract_search_url(collection, options.delete(:scopes), options.delete(:search_strategy))
9
9
  select_url = options.delete(:select_url) || extract_select_url(options.delete(:action))
10
10
 
11
11
  # tag options
@@ -25,9 +25,13 @@ module Searchify
25
25
  end
26
26
  end
27
27
 
28
- def extract_search_url(collection, scopes={})
29
- url = "#{searchify_path}/search/#{collection}.json?"
30
-
28
+ def extract_search_url(collection, scopes=nil, search_strategy=nil)
29
+ scopes ||= {}
30
+
31
+ url = "#{searchify_path}/search/#{collection}"
32
+ url << "/#{search_strategy}" if search_strategy
33
+ url << ".json?"
34
+
31
35
  scopes = searchify_scopes.merge(scopes) if Searchify::Config.scope_awareness
32
36
 
33
37
  url << scopes.map{ |k,v| "#{k}=#{v}" }.join('&')
@@ -60,7 +64,7 @@ class ActionView::Helpers::FormBuilder
60
64
  model_name = options.delete(:model_name) || extract_model_name(field)
61
65
  field_name = options.delete(:field_name) || extract_field_name(field)
62
66
  collection = options.delete(:collection) || extract_collection(model_name)
63
- search_url = options.delete(:search_url) || extract_search_url(collection, options.delete(:scopes) || {})
67
+ search_url = options.delete(:search_url) || extract_search_url(collection, options.delete(:scopes), options(:search_strategy))
64
68
 
65
69
  # field options
66
70
  options[:class] = [:searchify].push(options[:class]).flatten.compact
@@ -84,8 +88,13 @@ class ActionView::Helpers::FormBuilder
84
88
  model_name.to_s.tableize
85
89
  end
86
90
 
87
- def extract_search_url(collection, scopes={})
88
- "#{@template.searchify_path}/search/#{collection}.json?" + scopes.map{ |k,v| "#{k}=#{v}" }.join('&')
91
+ def extract_search_url(collection, scopes=nil, search_strategy=nil)
92
+ scopes ||= {}
93
+
94
+ url = "#{@template.searchify_path}/search/#{collection}"
95
+ url << "/#{search_strategy}" if search_strategy
96
+ url << ".json?"
97
+ url << scopes.map{ |k,v| "#{k}=#{v}" }.join('&')
89
98
  end
90
99
 
91
100
  def extract_model_name(field)
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  Searchify::Engine.routes.draw do
2
+ match '/search/:collection/:search_strategy' => "searchify#search"
2
3
  match '/search/:collection' => "searchify#search"
3
4
  end
@@ -1,3 +1,3 @@
1
1
  module Searchify
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
File without changes
metadata CHANGED
@@ -1,186 +1,157 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: searchify
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Christian Blais
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-01 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &9471040 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 1
30
- segments:
31
- - 3
32
- - 1
33
- - 1
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.1.1
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: jquery-rails
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *9471040
25
+ - !ruby/object:Gem::Dependency
26
+ name: jquery-rails
27
+ requirement: &9470580 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: sqlite3
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *9470580
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ requirement: &9469780 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
63
44
  type: :development
64
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *9469780
65
47
  description: Searchify provides a quick way to search your collections.
66
- email:
48
+ email:
67
49
  - christ.blais@gmail.com
68
50
  executables: []
69
-
70
51
  extensions: []
71
-
72
52
  extra_rdoc_files: []
73
-
74
- files:
75
- - app/assets/javascripts/searchify/searchify.js
76
- - app/controllers/searchify/searchify_controller.rb
53
+ files:
77
54
  - app/helpers/searchify/searchify_helper.rb
55
+ - app/controllers/searchify/searchify_controller.rb
56
+ - app/assets/javascripts/searchify/searchify.js
78
57
  - config/routes.rb
79
- - lib/searchify/config.rb
80
- - lib/searchify/controller.rb
81
- - lib/searchify/engine.rb
82
58
  - lib/searchify/version.rb
59
+ - lib/searchify/engine.rb
60
+ - lib/searchify/controller.rb
61
+ - lib/searchify/config.rb
83
62
  - lib/searchify.rb
84
63
  - lib/tasks/searchify_tasks.rake
85
64
  - MIT-LICENSE
86
65
  - Rakefile
87
66
  - README.md
88
- - test/dummy/app/assets/javascripts/application.js
89
- - test/dummy/app/assets/stylesheets/application.css
90
- - test/dummy/app/controllers/application_controller.rb
91
- - test/dummy/app/helpers/application_helper.rb
92
- - test/dummy/app/views/layouts/application.html.erb
93
- - test/dummy/config/application.rb
94
- - test/dummy/config/boot.rb
67
+ - test/functional/searchify/searchify_controller_test.rb
68
+ - test/unit/helpers/searchify/searchify_helper_test.rb
69
+ - test/searchify_test.rb
95
70
  - test/dummy/config/database.yml
71
+ - test/dummy/config/application.rb
96
72
  - test/dummy/config/environment.rb
97
- - test/dummy/config/environments/development.rb
98
- - test/dummy/config/environments/production.rb
99
- - test/dummy/config/environments/test.rb
100
- - test/dummy/config/initializers/backtrace_silencers.rb
101
- - test/dummy/config/initializers/inflections.rb
102
- - test/dummy/config/initializers/mime_types.rb
103
- - test/dummy/config/initializers/secret_token.rb
104
73
  - test/dummy/config/initializers/session_store.rb
74
+ - test/dummy/config/initializers/secret_token.rb
75
+ - test/dummy/config/initializers/mime_types.rb
105
76
  - test/dummy/config/initializers/wrap_parameters.rb
106
- - test/dummy/config/locales/en.yml
77
+ - test/dummy/config/initializers/inflections.rb
78
+ - test/dummy/config/initializers/backtrace_silencers.rb
107
79
  - test/dummy/config/routes.rb
80
+ - test/dummy/config/locales/en.yml
81
+ - test/dummy/config/environments/development.rb
82
+ - test/dummy/config/environments/test.rb
83
+ - test/dummy/config/environments/production.rb
84
+ - test/dummy/config/boot.rb
85
+ - test/dummy/Rakefile
108
86
  - test/dummy/config.ru
87
+ - test/dummy/app/helpers/application_helper.rb
88
+ - test/dummy/app/controllers/application_controller.rb
89
+ - test/dummy/app/views/layouts/application.html.erb
90
+ - test/dummy/app/assets/stylesheets/application.css
91
+ - test/dummy/app/assets/javascripts/application.js
92
+ - test/dummy/log/development.log
109
93
  - test/dummy/public/404.html
94
+ - test/dummy/public/favicon.ico
110
95
  - test/dummy/public/422.html
111
96
  - test/dummy/public/500.html
112
- - test/dummy/public/favicon.ico
113
- - test/dummy/Rakefile
114
97
  - test/dummy/script/rails
115
- - test/functional/searchify/searchify_controller_test.rb
116
- - test/integration/navigation_test.rb
117
- - test/searchify_test.rb
118
98
  - test/test_helper.rb
119
- - test/unit/helpers/searchify/searchify_helper_test.rb
120
- has_rdoc: true
99
+ - test/integration/navigation_test.rb
121
100
  homepage: http://github.com/christianblais/searchify
122
101
  licenses: []
123
-
124
102
  post_install_message:
125
103
  rdoc_options: []
126
-
127
- require_paths:
104
+ require_paths:
128
105
  - lib
129
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
130
107
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- hash: 3
135
- segments:
136
- - 0
137
- version: "0"
138
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
113
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 3
144
- segments:
145
- - 0
146
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
147
118
  requirements: []
148
-
149
119
  rubyforge_project:
150
- rubygems_version: 1.6.2
120
+ rubygems_version: 1.8.10
151
121
  signing_key:
152
122
  specification_version: 3
153
123
  summary: Search with ease!
154
- test_files:
155
- - test/dummy/app/assets/javascripts/application.js
156
- - test/dummy/app/assets/stylesheets/application.css
157
- - test/dummy/app/controllers/application_controller.rb
158
- - test/dummy/app/helpers/application_helper.rb
159
- - test/dummy/app/views/layouts/application.html.erb
160
- - test/dummy/config/application.rb
161
- - test/dummy/config/boot.rb
124
+ test_files:
125
+ - test/functional/searchify/searchify_controller_test.rb
126
+ - test/unit/helpers/searchify/searchify_helper_test.rb
127
+ - test/searchify_test.rb
162
128
  - test/dummy/config/database.yml
129
+ - test/dummy/config/application.rb
163
130
  - test/dummy/config/environment.rb
164
- - test/dummy/config/environments/development.rb
165
- - test/dummy/config/environments/production.rb
166
- - test/dummy/config/environments/test.rb
167
- - test/dummy/config/initializers/backtrace_silencers.rb
168
- - test/dummy/config/initializers/inflections.rb
169
- - test/dummy/config/initializers/mime_types.rb
170
- - test/dummy/config/initializers/secret_token.rb
171
131
  - test/dummy/config/initializers/session_store.rb
132
+ - test/dummy/config/initializers/secret_token.rb
133
+ - test/dummy/config/initializers/mime_types.rb
172
134
  - test/dummy/config/initializers/wrap_parameters.rb
173
- - test/dummy/config/locales/en.yml
135
+ - test/dummy/config/initializers/inflections.rb
136
+ - test/dummy/config/initializers/backtrace_silencers.rb
174
137
  - test/dummy/config/routes.rb
138
+ - test/dummy/config/locales/en.yml
139
+ - test/dummy/config/environments/development.rb
140
+ - test/dummy/config/environments/test.rb
141
+ - test/dummy/config/environments/production.rb
142
+ - test/dummy/config/boot.rb
143
+ - test/dummy/Rakefile
175
144
  - test/dummy/config.ru
145
+ - test/dummy/app/helpers/application_helper.rb
146
+ - test/dummy/app/controllers/application_controller.rb
147
+ - test/dummy/app/views/layouts/application.html.erb
148
+ - test/dummy/app/assets/stylesheets/application.css
149
+ - test/dummy/app/assets/javascripts/application.js
150
+ - test/dummy/log/development.log
176
151
  - test/dummy/public/404.html
152
+ - test/dummy/public/favicon.ico
177
153
  - test/dummy/public/422.html
178
154
  - test/dummy/public/500.html
179
- - test/dummy/public/favicon.ico
180
- - test/dummy/Rakefile
181
155
  - test/dummy/script/rails
182
- - test/functional/searchify/searchify_controller_test.rb
183
- - test/integration/navigation_test.rb
184
- - test/searchify_test.rb
185
156
  - test/test_helper.rb
186
- - test/unit/helpers/searchify/searchify_helper_test.rb
157
+ - test/integration/navigation_test.rb