innetra-acts_as_seekable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Gustavo Adrian Ortiz Monroy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ MIT-LICENSE
2
+ init.rb
3
+ Rakefile
4
+ README.rdoc
5
+ lib/active_record/acts/seekable.rb
6
+ Manifest
@@ -0,0 +1,74 @@
1
+ ActsAsSeekable
2
+ ==============
3
+
4
+ This plugin allows you to make your models seekable (searchable) by combining
5
+ filter params with order and search params. The values in the order and search params
6
+ will be used as lambda values for ordered_by and search named_scopes. Values in the
7
+ filter param will be treated as named_scopes. Since this plugin works based on
8
+ named_scopes, it will add an all_records and ordered_by named_scope to all models that have acts_as_seekable in them, you must create your own search named_scope for the seek (search) functionality to work and aditional named_scope for each filter you want.
9
+ When sending the filter param to the seek method, it is very important that you have
10
+ a named_scope called like the value of the parameter, or else it wont work.
11
+ You can specify if your seach will be paginated or not, it will use mislav-will_paginate
12
+ plugin to perform pagination, if you don't that gem installed acts_as_seekable
13
+ will ingnore the :paginate param.
14
+
15
+
16
+ Example
17
+ =======
18
+
19
+ Example with mislav-will_paginate:
20
+
21
+ acts_as_seekable :paginate => true
22
+ or
23
+ acts_as_seekable :paginate => :true
24
+ or
25
+ acts_as_seekable :paginate => "true"
26
+
27
+ named_scope :search, lambda { |search| conditions.... }
28
+
29
+
30
+ ----------------------------------------------------------------
31
+
32
+ Example without mislav-will_paginate:
33
+
34
+ acts_as_seekable #short way
35
+ or
36
+ acts_as_seekable :paginate => false #long way
37
+ or
38
+ acts_as_seekable :paginate => :false #long way
39
+ or
40
+ acts_as_seekable :paginate => "false" #long way
41
+
42
+ named_scope :search, lambda { |search| conditions.... }
43
+
44
+
45
+ -----------------------------------------------------------------
46
+
47
+ For a full example of an application working with acts_as_seekable visit
48
+ http://github.com/gusortiz/acts_as_seekable_example
49
+
50
+ Copyright (c) 2009 Gustavo Adrian Ortiz Monroy, released under the MIT license
51
+
52
+ MIT license
53
+ ===========
54
+
55
+ Copyright (c) 2009 Gustavo Adrian Ortiz Monroy
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ "Software"), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
71
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
72
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
73
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
74
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('acts_as_seekable', '0.1.0') do |e|
6
+ e.description = "Seekable (search) functionality for Rails applications"
7
+ e.url = "http://github.com/innetra/acts_as_seekable"
8
+ e.author = "Gus Ortiz"
9
+ e.email = "guspidey@gmail.com"
10
+ e.ignore_pattern = ["tmp/*", "script/*"]
11
+ e.development_dependencies = []
12
+ end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{acts_as_seekable}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Gus Ortiz"]
9
+ s.date = %q{2009-05-18}
10
+ s.description = %q{Seekable (search) functionality for Rails applications}
11
+ s.email = %q{guspidey@gmail.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/active_record/acts/seekable.rb"]
13
+ s.files = ["MIT-LICENSE", "init.rb", "Rakefile", "README.rdoc", "lib/active_record/acts/seekable.rb", "Manifest", "acts_as_seekable.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/innetra/acts_as_seekable}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Acts_as_seekable", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{acts_as_seekable}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Seekable (search) functionality for Rails applications}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift "#{File.dirname(__FILE__)}/lib"
2
+ require 'active_record/acts/seekable'
3
+ ActiveRecord::Base.class_eval { include ActiveRecord::Acts::Seekable }
@@ -0,0 +1,50 @@
1
+ # ActsAsSeekable
2
+ module ActiveRecord
3
+ module Acts
4
+ module Seekable
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ attr_accessor :config
13
+
14
+ def acts_as_seekable(options = {})
15
+ self.config = { :paginate => false }
16
+ self.config.update(options) if options.is_a?(Hash)
17
+ self.config[:paginate] = eval(config[:paginate].to_s) if config[:paginate].is_a?(Symbol)
18
+ self.config[:paginate] = eval(config[:paginate]) if config[:paginate].is_a?(String)
19
+ class_eval <<-EOV
20
+ include ActiveRecord::Acts::Seekable::ClassMethods
21
+ named_scope :all_records
22
+ named_scope :ordered_by, lambda { |order| { :order => order }}
23
+ EOV
24
+ end
25
+
26
+ def seek(params = {})
27
+ to_eval = "#{name}.all_records" if !params[:filter]
28
+
29
+ if scope = params[:filter]
30
+ to_eval = "#{name}.#{params[:filter]}" if scopes.has_key?(scope.to_sym)
31
+ end
32
+
33
+ if !params[:search].blank? && scopes.has_key?(:search)
34
+ to_eval << ".search('#{params[:search]}')"
35
+ end
36
+
37
+ to_eval << ".ordered_by('#{params[:order]}')" if params[:order]
38
+
39
+ if eval("#{name}.method_defined?(:paginate)") && config[:paginate] == true
40
+ to_eval << ".paginate(:page => params[:page],
41
+ :per_page => params[:per_page] || 5)"
42
+ end
43
+
44
+ eval(to_eval)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: innetra-acts_as_seekable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gus Ortiz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Seekable (search) functionality for Rails applications
17
+ email: guspidey@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - lib/active_record/acts/seekable.rb
25
+ files:
26
+ - MIT-LICENSE
27
+ - init.rb
28
+ - Rakefile
29
+ - README.rdoc
30
+ - lib/active_record/acts/seekable.rb
31
+ - Manifest
32
+ - acts_as_seekable.gemspec
33
+ has_rdoc: true
34
+ homepage: http://github.com/innetra/acts_as_seekable
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --line-numbers
38
+ - --inline-source
39
+ - --title
40
+ - Acts_as_seekable
41
+ - --main
42
+ - README.rdoc
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.2"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: acts_as_seekable
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Seekable (search) functionality for Rails applications
64
+ test_files: []
65
+