simple-search 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/simple_search.rb +8 -0
- data/lib/simple_search/active_record.rb +104 -0
- data/simple-search.gemspec +75 -0
- data/test/helper.rb +16 -0
- data/test/tables_models.rb +42 -0
- data/test/test_simple_search.rb +64 -0
- metadata +170 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
|
9
|
+
source :rubygems
|
10
|
+
|
11
|
+
gem "activerecord", "~> 3.1"
|
12
|
+
gem "activesupport", "~> 3.1"
|
13
|
+
gem "actionpack", "~> 3.1"
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem "shoulda", ">= 2.11"
|
17
|
+
gem "rdoc", "~> 3.12"
|
18
|
+
gem "bundler", "~> 1.0.0"
|
19
|
+
gem "jeweler", "~> 1.8.3"
|
20
|
+
gem "rcov", ">= 0"
|
21
|
+
gem 'sqlite3', '1.3.4'
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Allen Kim
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= simple-search
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to simple-search
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Allen Kim. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "simple-search"
|
18
|
+
gem.homepage = "http://github.com/bighostkim/simple-search"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{ActiveRecord searching/paging/sorting/grouping from url}
|
21
|
+
gem.description = %Q{
|
22
|
+
Translates url commands for searching, paging, sorting, groupion against ActiveRecord and its associations.
|
23
|
+
Provides view helpers including links for order and urls for search, group, and page.
|
24
|
+
}
|
25
|
+
gem.email = "bighostkim@gmail.com"
|
26
|
+
gem.authors = ["Allen Kim"]
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'rcov/rcovtask'
|
39
|
+
Rcov::RcovTask.new do |test|
|
40
|
+
test.libs << 'test'
|
41
|
+
test.pattern = 'test/**/test_*.rb'
|
42
|
+
test.verbose = true
|
43
|
+
test.rcov_opts << '--exclude "gems/*"'
|
44
|
+
end
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rdoc/task'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "simple-search #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_support'
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_controller'
|
5
|
+
require 'simple_search/active_record'
|
6
|
+
|
7
|
+
ActiveRecord::Base.send(:include, SimpleSearch::ActiveRecord)
|
8
|
+
#ActionController::Base.helper(MetaSearch::Helpers::UrlHelper)
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module SimpleSearch
|
2
|
+
OP_MAP = { :gt=>">", :ge=>">=", :lt=>"<", :le=>"<=", :eq=>"=", :ne=>"<>", :in=>"IN",
|
3
|
+
:bt=>"BETWEEN", :between => "BETWEEN",
|
4
|
+
:sw=>"LIKE", :startswith => "LIKE",
|
5
|
+
:ew=>"LIKE", :endswith => "LIKE",
|
6
|
+
:ct=>"LIKE", :contains => "LIKE", :like => "LIKE",
|
7
|
+
:nc=>"NOT LIKE", :notcontains => "NOT LIKE", :notlike=>"NOT LIKE",
|
8
|
+
:is=>"IS",
|
9
|
+
:it=> 'IS NOT', :isnot => "IS NOT"
|
10
|
+
}
|
11
|
+
|
12
|
+
class Error < Exception; end
|
13
|
+
|
14
|
+
module ActiveRecord
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def simplesearch(params={})
|
22
|
+
|
23
|
+
arel = self.scoped unless self.is_a?(::ActiveRecord::Relation)
|
24
|
+
params, where_params=filtered_params(params) # validate params
|
25
|
+
arel = with_ss_where(arel,where_params)
|
26
|
+
arel = with_ss_group(arel,params['group_by'])
|
27
|
+
arel = with_ss_order(arel,params['order_by'])
|
28
|
+
#arel = with_ss_limit(arel,params)
|
29
|
+
#arel = with_ss_order(arel,params)
|
30
|
+
arel
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :ss, :simplesearch unless respond_to?(:ss)
|
34
|
+
|
35
|
+
def filtered_params(params)
|
36
|
+
where_params = {}
|
37
|
+
other_params = {}
|
38
|
+
params.each do |key,value|
|
39
|
+
if ["group_by","page_by","page_no","order_by"].include?(key)
|
40
|
+
other_params[key]=value
|
41
|
+
else
|
42
|
+
matches = /(.*)_([a-z]+)$/.match(key)
|
43
|
+
if matches.length==3
|
44
|
+
all, col, op = matches.to_a
|
45
|
+
operands = SimpleSearch::OP_MAP.keys
|
46
|
+
if operands.include?(op.to_sym)
|
47
|
+
where_params[key]=value
|
48
|
+
else
|
49
|
+
logger.warning("SimpleSearch ignored #{key}. operand must be one of #{operands}") unless logger.nil?
|
50
|
+
end
|
51
|
+
else
|
52
|
+
logger.warning("SimpleSearch ignored #{key}. it requires to end with _<operands>") unless logger.nil?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
[other_params, where_params]
|
57
|
+
end
|
58
|
+
|
59
|
+
def with_ss_where(arel,params={})
|
60
|
+
params.each do |key,value|
|
61
|
+
matches = /(.*)_([a-z]+)$/.match(key)
|
62
|
+
all, col, op = matches.to_a
|
63
|
+
where_col = col =~ /\./ ? col : "#{arel.table_name}.#{col}" #if no table name, the add it
|
64
|
+
where_value = case op.to_sym
|
65
|
+
when :gt,:ge,:lt,:le,:eq,:ne then value
|
66
|
+
when :sw then "#{value}%" # LIKE
|
67
|
+
when :ew then "%#{value}" # LIKE
|
68
|
+
when :ct,:contains,:like then "%#{value}%" # LIKE
|
69
|
+
when :nc,:notcontains,:notlike then "%#{value}%" # NOT LIKE
|
70
|
+
when :is, :isnot, :it
|
71
|
+
if ["NULL","null"].include?(value) then nil
|
72
|
+
elsif ["TRUE","true"].include?(value) then true
|
73
|
+
elsif ["FALSE","false"].include?(value) then false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
if op.to_sym==:in
|
77
|
+
arel = arel.where("#{where_col}"=>value.split(','))
|
78
|
+
elsif [:bt, :between].include? op.to_sym
|
79
|
+
first,second = value.split('..')
|
80
|
+
arel = arel.where("#{where_col}"=>Range.new(first,second))
|
81
|
+
else
|
82
|
+
arel = arel.where("#{where_col} #{SimpleSearch::OP_MAP[op.to_sym]} ?", where_value)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
arel
|
86
|
+
end
|
87
|
+
|
88
|
+
def with_ss_group(arel,group_by)
|
89
|
+
arel= arel.group(group_by) if group_by
|
90
|
+
arel
|
91
|
+
end
|
92
|
+
|
93
|
+
def with_ss_order(arel,order_by)
|
94
|
+
arel= arel.order(order_by) if order_by
|
95
|
+
arel
|
96
|
+
end
|
97
|
+
|
98
|
+
def with_ss_limit(arel,params={})
|
99
|
+
# TODO
|
100
|
+
end
|
101
|
+
|
102
|
+
end # end class methods
|
103
|
+
end # end module ActiveRecord
|
104
|
+
end # end module SimpleSearch
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "simple-search"
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Allen Kim"]
|
12
|
+
s.date = "2012-03-10"
|
13
|
+
s.description = "\n\t\tTranslates url commands for searching, paging, sorting, groupion against ActiveRecord and its associations.\n\t\tProvides view helpers including links for order and urls for search, group, and page.\n\t"
|
14
|
+
s.email = "bighostkim@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/simple_search.rb",
|
27
|
+
"lib/simple_search/active_record.rb",
|
28
|
+
"simple-search.gemspec",
|
29
|
+
"test/helper.rb",
|
30
|
+
"test/tables_models.rb",
|
31
|
+
"test/test_simple_search.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/bighostkim/simple-search"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.15"
|
37
|
+
s.summary = "ActiveRecord searching/paging/sorting/grouping from url"
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 3.1"])
|
44
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.1"])
|
45
|
+
s.add_runtime_dependency(%q<actionpack>, ["~> 3.1"])
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.11"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<sqlite3>, ["= 1.3.4"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1"])
|
54
|
+
s.add_dependency(%q<activesupport>, ["~> 3.1"])
|
55
|
+
s.add_dependency(%q<actionpack>, ["~> 3.1"])
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 2.11"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
s.add_dependency(%q<sqlite3>, ["= 1.3.4"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<activerecord>, ["~> 3.1"])
|
65
|
+
s.add_dependency(%q<activesupport>, ["~> 3.1"])
|
66
|
+
s.add_dependency(%q<actionpack>, ["~> 3.1"])
|
67
|
+
s.add_dependency(%q<shoulda>, [">= 2.11"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
s.add_dependency(%q<sqlite3>, ["= 1.3.4"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'simple_search'
|
16
|
+
require 'tables_models.rb'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# setting database tables
|
2
|
+
root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
ActiveRecord::Base.establish_connection(
|
4
|
+
:adapter => "sqlite3",
|
5
|
+
:database => "#{root}/simpesearch_gem_test.sqlite3"
|
6
|
+
)
|
7
|
+
|
8
|
+
#require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
9
|
+
|
10
|
+
# drop tables
|
11
|
+
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'posts'")
|
12
|
+
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'comments'")
|
13
|
+
|
14
|
+
# create tables
|
15
|
+
ActiveRecord::Base.connection.create_table(:posts) do |t|
|
16
|
+
t.string :subject
|
17
|
+
t.text :body
|
18
|
+
end
|
19
|
+
ActiveRecord::Base.connection.create_table(:comments) do |t|
|
20
|
+
t.string :post_id
|
21
|
+
t.text :body
|
22
|
+
t.boolean :spam_flag
|
23
|
+
end
|
24
|
+
|
25
|
+
# insert tables
|
26
|
+
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (1, 'subject foo','body foo') ")
|
27
|
+
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (2, 'subject bar','body bar') ")
|
28
|
+
ActiveRecord::Base.connection.execute("INSERT INTO posts (id,subject,body) VALUES (3, 'subject fooz','body baz') ")
|
29
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (11, 1,'post1 comment foo') ")
|
30
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (12, 1,'post1 comment bar') ")
|
31
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (21, 2,'post2 comment foo') ")
|
32
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body) VALUES (22, 2,'post2 comment bar') ")
|
33
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body,spam_flag) VALUES (31, 3,'post3 comment foo', 1) ")
|
34
|
+
ActiveRecord::Base.connection.execute("INSERT INTO comments (id,post_id,body,spam_flag) VALUES (32, 3,'post3 comment bar', 0) ")
|
35
|
+
|
36
|
+
# models
|
37
|
+
class Post < ActiveRecord::Base
|
38
|
+
has_many :comments
|
39
|
+
end
|
40
|
+
class Comment < ActiveRecord::Base
|
41
|
+
belongs_to :post
|
42
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSimpleSearch < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "work with arel where conditions" do
|
6
|
+
posts_comments = Post.select('posts.*, comments.body as comment').joins(:comments)
|
7
|
+
result = posts_comments.simplesearch('id_eq'=>1, 'subject_eq'=>'subject foo', 'body_eq'=>'body foo')
|
8
|
+
assert_equal 1, result.first.id
|
9
|
+
|
10
|
+
result = posts_comments.simplesearch('id_gt'=>1, 'id_lt'=>3)
|
11
|
+
assert_equal 2, result.first.id
|
12
|
+
|
13
|
+
result = posts_comments.simplesearch('id_ge'=>1, 'id_le'=>3)
|
14
|
+
assert_equal 6, result.length
|
15
|
+
|
16
|
+
result = posts_comments.simplesearch('id_ne'=>1)
|
17
|
+
assert_equal 4, result.length
|
18
|
+
|
19
|
+
result = posts_comments.simplesearch('id_in'=>'1,2')
|
20
|
+
assert_equal 1, result.first.id
|
21
|
+
assert_equal 2, result.last.id
|
22
|
+
|
23
|
+
result = posts_comments.simplesearch('id_bt'=>'1..3')
|
24
|
+
assert_equal 1, result.first.id
|
25
|
+
assert_equal 3, result.last.id
|
26
|
+
|
27
|
+
result = posts_comments.simplesearch('subject_sw'=>'subject')
|
28
|
+
assert_equal 6, result.length
|
29
|
+
|
30
|
+
result = posts_comments.simplesearch('subject_ew'=>'foo')
|
31
|
+
assert_equal 2, result.length
|
32
|
+
|
33
|
+
result = posts_comments.simplesearch('body_ct'=>'body')
|
34
|
+
assert_equal 6, result.length
|
35
|
+
|
36
|
+
result = posts_comments.simplesearch('body_nc'=>'foo')
|
37
|
+
assert_equal 4, result.length
|
38
|
+
|
39
|
+
result = posts_comments.simplesearch('comments.spam_flag_is'=>'NULL')
|
40
|
+
assert_equal 4, result.length
|
41
|
+
|
42
|
+
result = posts_comments.simplesearch('comments.spam_flag_isnot'=>'NULL')
|
43
|
+
assert_equal 2, result.length
|
44
|
+
end
|
45
|
+
|
46
|
+
should "work with arel group conditions" do
|
47
|
+
posts_comments = Post.select('posts.*, count(comments.id) as num_comment').joins(:comments)
|
48
|
+
result = posts_comments.simplesearch('group_by'=>'posts.id')
|
49
|
+
assert_equal 3, result.length
|
50
|
+
end
|
51
|
+
|
52
|
+
should "work with arel order conditions" do
|
53
|
+
posts_comments = Post.select('posts.*, comments.id as comment_id, comments.body as comment').joins(:comments)
|
54
|
+
result = posts_comments.simplesearch('order_by'=>'comment_id')
|
55
|
+
assert_equal 11, result.first.comment_id
|
56
|
+
result = posts_comments.simplesearch('order_by'=>'comment_id desc')
|
57
|
+
assert_equal 32, result.first.comment_id
|
58
|
+
end
|
59
|
+
|
60
|
+
should "work with arel limit conditions" do
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Allen Kim
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-03-10 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "3.1"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "3.1"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: actionpack
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "3.1"
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: shoulda
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "2.11"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rdoc
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "3.12"
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.0.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: jeweler
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.8.3
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: rcov
|
94
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: sqlite3
|
105
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - "="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.3.4
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *id009
|
114
|
+
description: "\n\
|
115
|
+
\t\tTranslates url commands for searching, paging, sorting, groupion against ActiveRecord and its associations.\n\
|
116
|
+
\t\tProvides view helpers including links for order and urls for search, group, and page.\n\
|
117
|
+
\t"
|
118
|
+
email: bighostkim@gmail.com
|
119
|
+
executables: []
|
120
|
+
|
121
|
+
extensions: []
|
122
|
+
|
123
|
+
extra_rdoc_files:
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.rdoc
|
126
|
+
files:
|
127
|
+
- .document
|
128
|
+
- Gemfile
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.rdoc
|
131
|
+
- Rakefile
|
132
|
+
- VERSION
|
133
|
+
- lib/simple_search.rb
|
134
|
+
- lib/simple_search/active_record.rb
|
135
|
+
- simple-search.gemspec
|
136
|
+
- test/helper.rb
|
137
|
+
- test/tables_models.rb
|
138
|
+
- test/test_simple_search.rb
|
139
|
+
homepage: http://github.com/bighostkim/simple-search
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 2459026480116491864
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.15
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: ActiveRecord searching/paging/sorting/grouping from url
|
169
|
+
test_files: []
|
170
|
+
|