searchify 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,7 +25,7 @@ Add both jquery-ui and searchify to your `app/assets/javascripts/application.js`
25
25
 
26
26
  Usage
27
27
  -----
28
- #### Autocomplete search
28
+ ### Autocomplete search
29
29
 
30
30
  Searchify is intented to be used on a per model basis. You type, you choose, you are redirected to the chosen resource show page.
31
31
  Calling it on an index page, it infers the model to be searched with the controller name, or the `resource_class` helper, if it exists.
@@ -44,7 +44,7 @@ For example, to land on the edit page, you could write:
44
44
 
45
45
  <%= autocomplete :select_url => "/posts/(id)/edit" %>
46
46
 
47
- #### In place autocomplete
47
+ ### In place autocomplete
48
48
 
49
49
  Searchify can also be used in a form. For example, let's say that a post belongs to a user of your choice.:
50
50
 
@@ -57,7 +57,7 @@ Searchify can also be used in a form. For example, let's say that a post belongs
57
57
 
58
58
  Searchify will include a `user_id` field in your form, which will be automatically populated.
59
59
 
60
- #### Scopes
60
+ ### Scopes
61
61
 
62
62
  Searchify is scopes aware. Let's say you are here:
63
63
 
@@ -65,7 +65,16 @@ Searchify is scopes aware. Let's say you are here:
65
65
 
66
66
  Assuming your `Post` model responds to the `created_by` method, it will be included in the search.
67
67
 
68
- #### Search stategies
68
+ ### Configuration
69
+
70
+ You can always override the defaults with an initializer. Options are as follow:
71
+
72
+ Searchify::Config.configure do |config|
73
+ config.scope_exclusion = %w( controller action format collection term page )
74
+ config.columns = %w( name title abbreviation )
75
+ end
76
+
77
+ ### Search stategies
69
78
 
70
79
  By default, Searchify does a case insensitive search on `name`, `title` and `abbreviation` fields of your models, if they exist. You can of course specify
71
80
  a custom search strategy by defining a class method named `search_strategy` in your model. It should returns an array of hash.
@@ -7,8 +7,6 @@ module Searchify
7
7
 
8
8
  layout false
9
9
 
10
- DEFAULT_COLUMNS = %w( name title abbreviation )
11
-
12
10
  def search
13
11
  resource_class = params[:collection].classify.constantize
14
12
  search_term = params[:term]
@@ -17,7 +15,7 @@ module Searchify
17
15
  collection = if resource_class.respond_to?(:search_strategy)
18
16
  resource_class.search_strategy(search_term, current_scopes)
19
17
  else
20
- columns = DEFAULT_COLUMNS & resource_class.column_names
18
+ columns = Config.columns & resource_class.column_names
21
19
 
22
20
  scoped = resource_class.where( columns.map{ |c| "(#{c} #{search_keyword} :term)" }.join(' OR '), :term => "%#{search_term}%")
23
21
 
data/lib/searchify.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "searchify/config"
1
2
  require "searchify/controller"
2
3
  require "searchify/engine"
3
4
 
@@ -0,0 +1,33 @@
1
+ module Searchify
2
+ module Config
3
+ class << self
4
+ attr_accessor :scope_exclusion, :columns
5
+
6
+ def configure(&block)
7
+ @configuration = block
8
+ end
9
+
10
+ def configure!
11
+ @configuration.call(self) if @configuration
12
+ end
13
+
14
+ protected
15
+
16
+ def init!
17
+ @defaults = {
18
+ :@scope_exclusion => %w( controller action format collection term page ),
19
+ :@columns => %w( name title abbreviation )
20
+ }
21
+ end
22
+
23
+ def reset!
24
+ @defaults.each do |k,v|
25
+ instance_variable_set(k,v)
26
+ end
27
+ end
28
+ end
29
+
30
+ init!
31
+ reset!
32
+ end
33
+ end
@@ -1,16 +1,16 @@
1
1
  module Searchify
2
2
  module Controller
3
- SCOPE_EXCLUSION = %w( controller action format collection term page )
4
-
5
3
  def self.included(base)
6
4
  base.class_eval do
7
5
  include InstanceMethods
8
6
  end
7
+
8
+ Searchify::Config.configure!
9
9
  end
10
10
 
11
11
  module InstanceMethods
12
12
  def searchify_scopes
13
- params.except(*SCOPE_EXCLUSION)
13
+ params.except(*Config.scope_exclusion)
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Searchify
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-13 00:00:00.000000000Z
12
+ date: 2011-11-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &21309620 !ruby/object:Gem::Requirement
16
+ requirement: &14547660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21309620
24
+ version_requirements: *14547660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &21309180 !ruby/object:Gem::Requirement
27
+ requirement: &14547200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21309180
35
+ version_requirements: *14547200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &21308660 !ruby/object:Gem::Requirement
38
+ requirement: &14546640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21308660
46
+ version_requirements: *14546640
47
47
  description: Searchify provides a quick way to search your collections.
48
48
  email:
49
49
  - christ.blais@gmail.com
@@ -58,6 +58,7 @@ files:
58
58
  - lib/searchify/version.rb
59
59
  - lib/searchify/engine.rb
60
60
  - lib/searchify/controller.rb
61
+ - lib/searchify/config.rb
61
62
  - lib/searchify.rb
62
63
  - lib/tasks/searchify_tasks.rake
63
64
  - MIT-LICENSE