joost-searchlogic 2.1.5.3 → 2.1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +14 -3
- data/VERSION.yml +1 -1
- data/lib/searchlogic.rb +4 -2
- data/lib/searchlogic/named_scopes/{associations.rb → association_conditions.rb} +4 -18
- data/lib/searchlogic/named_scopes/association_ordering.rb +27 -0
- data/lib/searchlogic/named_scopes/conditions.rb +5 -0
- data/lib/searchlogic/named_scopes/ordering.rb +2 -2
- data/lib/searchlogic/search.rb +2 -1
- data/searchlogic.gemspec +8 -5
- data/spec/named_scopes/{associations_spec.rb → association_conditions_spec.rb} +1 -17
- data/spec/named_scopes/association_ordering_spec.rb +19 -0
- data/spec/named_scopes/conditions_spec.rb +4 -0
- data/spec/named_scopes/ordering_spec.rb +4 -0
- data/spec/search_spec.rb +7 -0
- data/spec/spec_helper.rb +5 -1
- metadata +8 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
-
== 2.1.
|
1
|
+
== 2.1.7
|
2
2
|
|
3
|
-
*
|
3
|
+
* Add support for time zones in the Search class when type casting to Time objects.
|
4
|
+
|
5
|
+
== 2.1.6 released 2009-07-13
|
6
|
+
|
7
|
+
* Fix bug when trying to set conditions on conflicting column names with associations. Ex: User.has_many :orders, User.order_count_gt(10) would raise an exception because it was trying to set conditions on the count column for the orders table.
|
8
|
+
|
9
|
+
== 2.1.5 released 2009-07-12
|
10
|
+
|
11
|
+
* Check for the existence of id before undefining it, fixes bug in ruby 1.9
|
12
|
+
|
13
|
+
== 2.1.4 released 2009-07-12
|
14
|
+
|
15
|
+
* Add ActiveRecordConsistency module to help AR remove duplicate joins easier.
|
4
16
|
|
5
17
|
== 2.1.3 released 2009-07-12
|
6
18
|
|
7
19
|
* Added a no conflic resolution for other libraries already using the "search" method. If you have a conflict, use "searchlogic".
|
8
20
|
* Put the hidden order field in a div, to be valid XHTML.
|
9
|
-
* Add ActiveRecordConsistency module to help AR remove duplicate joins easier.
|
10
21
|
|
11
22
|
== 2.1.2 released 2009-07-04
|
12
23
|
|
data/VERSION.yml
CHANGED
data/lib/searchlogic.rb
CHANGED
@@ -3,7 +3,8 @@ require "searchlogic/core_ext/object"
|
|
3
3
|
require "searchlogic/active_record_consistency"
|
4
4
|
require "searchlogic/named_scopes/conditions"
|
5
5
|
require "searchlogic/named_scopes/ordering"
|
6
|
-
require "searchlogic/named_scopes/
|
6
|
+
require "searchlogic/named_scopes/association_conditions"
|
7
|
+
require "searchlogic/named_scopes/association_ordering"
|
7
8
|
require "searchlogic/named_scopes/alias_scope"
|
8
9
|
require "searchlogic/search"
|
9
10
|
|
@@ -11,7 +12,8 @@ Proc.send(:include, Searchlogic::CoreExt::Proc)
|
|
11
12
|
Object.send(:include, Searchlogic::CoreExt::Object)
|
12
13
|
ActiveRecord::Base.extend(Searchlogic::NamedScopes::Conditions)
|
13
14
|
ActiveRecord::Base.extend(Searchlogic::NamedScopes::Ordering)
|
14
|
-
ActiveRecord::Base.extend(Searchlogic::NamedScopes::
|
15
|
+
ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationConditions)
|
16
|
+
ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationOrdering)
|
15
17
|
ActiveRecord::Base.extend(Searchlogic::NamedScopes::AliasScope)
|
16
18
|
ActiveRecord::Base.extend(Searchlogic::Search::Implementation)
|
17
19
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Searchlogic
|
2
2
|
module NamedScopes
|
3
3
|
# Handles dynamically creating named scopes for associations.
|
4
|
-
module
|
4
|
+
module AssociationConditions
|
5
5
|
def condition?(name) # :nodoc:
|
6
6
|
super || association_condition?(name) || association_alias_condition?(name)
|
7
7
|
end
|
@@ -43,9 +43,6 @@ module Searchlogic
|
|
43
43
|
elsif details = association_alias_condition_details(name)
|
44
44
|
create_association_alias_condition(details[:association], details[:column], details[:condition], args)
|
45
45
|
send(name, *args)
|
46
|
-
elsif details = association_ordering_condition_details(name)
|
47
|
-
create_association_ordering_condition(details[:association], details[:order_as], details[:column], args)
|
48
|
-
send(name, *args)
|
49
46
|
else
|
50
47
|
super
|
51
48
|
end
|
@@ -53,7 +50,7 @@ module Searchlogic
|
|
53
50
|
|
54
51
|
def association_condition_details(name)
|
55
52
|
associations = reflect_on_all_associations.collect { |assoc| assoc.name }
|
56
|
-
if name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::PRIMARY_CONDITIONS.join("|")})$/
|
53
|
+
if !local_condition?(name) && name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::PRIMARY_CONDITIONS.join("|")})$/
|
57
54
|
{:association => $1, :column => $2, :condition => $3}
|
58
55
|
end
|
59
56
|
end
|
@@ -64,7 +61,7 @@ module Searchlogic
|
|
64
61
|
|
65
62
|
def association_alias_condition_details(name)
|
66
63
|
associations = reflect_on_all_associations.collect { |assoc| assoc.name }
|
67
|
-
if name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::ALIAS_CONDITIONS.join("|")})$/
|
64
|
+
if !local_condition?(name) && name.to_s =~ /^(#{associations.join("|")})_(\w+)_(#{Conditions::ALIAS_CONDITIONS.join("|")})$/
|
68
65
|
{:association => $1, :column => $2, :condition => $3}
|
69
66
|
end
|
70
67
|
end
|
@@ -76,18 +73,7 @@ module Searchlogic
|
|
76
73
|
send(primary_name, *args) # go back to method_missing and make sure we create the method
|
77
74
|
(class << self; self; end).class_eval { alias_method alias_name, primary_name }
|
78
75
|
end
|
79
|
-
|
80
|
-
def association_ordering_condition_details(name)
|
81
|
-
associations = reflect_on_all_associations.collect { |assoc| assoc.name }
|
82
|
-
if name.to_s =~ /^(ascend|descend)_by_(#{associations.join("|")})_(\w+)$/
|
83
|
-
{:order_as => $1, :association => $2, :column => $3} unless column_names.include?("#{$2}_#{$3}")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def create_association_ordering_condition(association_name, order_as, column, args)
|
88
|
-
named_scope("#{order_as}_by_#{association_name}_#{column}", association_condition_options(association_name, "#{order_as}_by_#{column}", args))
|
89
|
-
end
|
90
|
-
|
76
|
+
|
91
77
|
def association_condition_options(association_name, association_condition, args)
|
92
78
|
association = reflect_on_association(association_name.to_sym)
|
93
79
|
scope = association.klass.send(association_condition, *args)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Searchlogic
|
2
|
+
module NamedScopes
|
3
|
+
# Handles dynamically creating named scopes for associations.
|
4
|
+
module AssociationOrdering
|
5
|
+
private
|
6
|
+
def method_missing(name, *args, &block)
|
7
|
+
if details = association_ordering_condition_details(name)
|
8
|
+
create_association_ordering_condition(details[:association], details[:order_as], details[:column], args)
|
9
|
+
send(name, *args)
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def association_ordering_condition_details(name)
|
16
|
+
associations = reflect_on_all_associations.collect { |assoc| assoc.name }
|
17
|
+
if !local_condition?(name) && name.to_s =~ /^(ascend|descend)_by_(#{associations.join("|")})_(\w+)$/
|
18
|
+
{:order_as => $1, :association => $2, :column => $3}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_association_ordering_condition(association_name, order_as, column, args)
|
23
|
+
named_scope("#{order_as}_by_#{association_name}_#{column}", association_condition_options(association_name, "#{order_as}_by_#{column}", args))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -95,6 +95,11 @@ module Searchlogic
|
|
95
95
|
|
96
96
|
# Is the name of the method a valid condition that can be dynamically created?
|
97
97
|
def condition?(name)
|
98
|
+
local_condition?(name)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Is the condition for a local column, not an association
|
102
|
+
def local_condition?(name)
|
98
103
|
primary_condition?(name) || alias_condition?(name)
|
99
104
|
end
|
100
105
|
|
@@ -2,7 +2,7 @@ module Searchlogic
|
|
2
2
|
module NamedScopes
|
3
3
|
# Handles dynamically creating named scopes for orderin by columns.
|
4
4
|
module Ordering
|
5
|
-
def
|
5
|
+
def local_condition?(name) # :nodoc:
|
6
6
|
super || order_condition?(name)
|
7
7
|
end
|
8
8
|
|
@@ -37,7 +37,7 @@ module Searchlogic
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def order_condition_details(name)
|
40
|
-
if name.to_s =~ /^(ascend|descend)_by_(
|
40
|
+
if name.to_s =~ /^(ascend|descend)_by_(#{column_names.join("|")})$/
|
41
41
|
{:order_as => $1, :column => $2}
|
42
42
|
elsif name.to_s =~ /^order$/
|
43
43
|
{}
|
data/lib/searchlogic/search.rb
CHANGED
@@ -143,7 +143,8 @@ module Searchlogic
|
|
143
143
|
# with the other models.
|
144
144
|
column_for_type_cast = ActiveRecord::ConnectionAdapters::Column.new("", nil)
|
145
145
|
column_for_type_cast.instance_variable_set(:@type, type)
|
146
|
-
column_for_type_cast.type_cast(value)
|
146
|
+
value = column_for_type_cast.type_cast(value)
|
147
|
+
Time.zone && value.is_a?(Time) ? value.in_time_zone : value
|
147
148
|
end
|
148
149
|
end
|
149
150
|
end
|
data/searchlogic.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{searchlogic}
|
5
|
-
s.version = "2.1.
|
5
|
+
s.version = "2.1.7.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Johnson of Binary Logic"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-13}
|
10
10
|
s.email = %q{bjohnson@binarylogic.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -25,7 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
"lib/searchlogic/core_ext/object.rb",
|
26
26
|
"lib/searchlogic/core_ext/proc.rb",
|
27
27
|
"lib/searchlogic/named_scopes/alias_scope.rb",
|
28
|
-
"lib/searchlogic/named_scopes/
|
28
|
+
"lib/searchlogic/named_scopes/association_conditions.rb",
|
29
|
+
"lib/searchlogic/named_scopes/association_ordering.rb",
|
29
30
|
"lib/searchlogic/named_scopes/conditions.rb",
|
30
31
|
"lib/searchlogic/named_scopes/ordering.rb",
|
31
32
|
"lib/searchlogic/rails_helpers.rb",
|
@@ -35,7 +36,8 @@ Gem::Specification.new do |s|
|
|
35
36
|
"spec/core_ext/object_spec.rb",
|
36
37
|
"spec/core_ext/proc_spec.rb",
|
37
38
|
"spec/named_scopes/alias_scope_spec.rb",
|
38
|
-
"spec/named_scopes/
|
39
|
+
"spec/named_scopes/association_conditions_spec.rb",
|
40
|
+
"spec/named_scopes/association_ordering_spec.rb",
|
39
41
|
"spec/named_scopes/conditions_spec.rb",
|
40
42
|
"spec/named_scopes/ordering_spec.rb",
|
41
43
|
"spec/search_spec.rb",
|
@@ -51,7 +53,8 @@ Gem::Specification.new do |s|
|
|
51
53
|
"spec/core_ext/object_spec.rb",
|
52
54
|
"spec/core_ext/proc_spec.rb",
|
53
55
|
"spec/named_scopes/alias_scope_spec.rb",
|
54
|
-
"spec/named_scopes/
|
56
|
+
"spec/named_scopes/association_conditions_spec.rb",
|
57
|
+
"spec/named_scopes/association_ordering_spec.rb",
|
55
58
|
"spec/named_scopes/conditions_spec.rb",
|
56
59
|
"spec/named_scopes/ordering_spec.rb",
|
57
60
|
"spec/search_spec.rb",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Association Conditions" do
|
4
4
|
it "should create a named scope" do
|
5
5
|
Company.users_username_like("bjohnson").proxy_options.should == User.username_like("bjohnson").proxy_options.merge(:joins => :users)
|
6
6
|
end
|
@@ -50,22 +50,6 @@ describe "Associations" do
|
|
50
50
|
Company.users_orders_total_gt(10).proxy_options.should == Order.total_gt(10).proxy_options.merge(:joins => {:users => :orders})
|
51
51
|
end
|
52
52
|
|
53
|
-
it "should allow ascending" do
|
54
|
-
Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should allow descending" do
|
58
|
-
Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should allow deep ascending" do
|
62
|
-
Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should allow deep descending" do
|
66
|
-
Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
67
|
-
end
|
68
|
-
|
69
53
|
it "should include optional associations" do
|
70
54
|
pending # this is a problem with using inner joins and left outer joins
|
71
55
|
Company.create
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe "Association Ordering" do
|
4
|
+
it "should allow ascending" do
|
5
|
+
Company.ascend_by_users_username.proxy_options.should == User.ascend_by_username.proxy_options.merge(:joins => :users)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should allow descending" do
|
9
|
+
Company.descend_by_users_username.proxy_options.should == User.descend_by_username.proxy_options.merge(:joins => :users)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should allow deep ascending" do
|
13
|
+
Company.ascend_by_users_orders_total.proxy_options.should == Order.ascend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow deep descending" do
|
17
|
+
Company.descend_by_users_orders_total.proxy_options.should == Order.descend_by_total.proxy_options.merge(:joins => {:users => :orders})
|
18
|
+
end
|
19
|
+
end
|
@@ -20,4 +20,8 @@ describe "Ordering" do
|
|
20
20
|
it "should have order" do
|
21
21
|
User.order("ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should have priorty to columns over conflicting association columns" do
|
25
|
+
Company.ascend_by_users_count
|
26
|
+
end
|
23
27
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -226,6 +226,13 @@ describe "Search" do
|
|
226
226
|
search.created_at_after.should == Time.parse("Jan 1, 2009 9:33AM")
|
227
227
|
end
|
228
228
|
|
229
|
+
it "should convert the time to the current zone" do
|
230
|
+
search = Order.search
|
231
|
+
now = Time.now
|
232
|
+
search.created_at_after = now
|
233
|
+
search.created_at_after.should == now.in_time_zone
|
234
|
+
end
|
235
|
+
|
229
236
|
it "should be an Array and cast it's values given ['1', '2', '3']" do
|
230
237
|
search = Order.search
|
231
238
|
search.id_equals_any = ["1", "2", "3"]
|
data/spec/spec_helper.rb
CHANGED
@@ -3,6 +3,9 @@ require 'rubygems'
|
|
3
3
|
require 'ruby-debug'
|
4
4
|
require 'activerecord'
|
5
5
|
|
6
|
+
ENV['TZ'] = 'UTC'
|
7
|
+
Time.zone = 'Eastern Time (US & Canada)'
|
8
|
+
|
6
9
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
7
10
|
ActiveRecord::Base.configurations = true
|
8
11
|
|
@@ -11,6 +14,7 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
11
14
|
create_table :companies do |t|
|
12
15
|
t.datetime :created_at
|
13
16
|
t.datetime :updated_at
|
17
|
+
t.integer :users_count, :default => 0
|
14
18
|
end
|
15
19
|
|
16
20
|
create_table :users do |t|
|
@@ -50,7 +54,7 @@ Spec::Runner.configure do |config|
|
|
50
54
|
end
|
51
55
|
|
52
56
|
class User < ActiveRecord::Base
|
53
|
-
belongs_to :company
|
57
|
+
belongs_to :company, :counter_cache => true
|
54
58
|
has_many :orders, :dependent => :destroy
|
55
59
|
alias_scope :username_has, lambda { |value| username_like(value) }
|
56
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joost-searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -44,7 +44,8 @@ files:
|
|
44
44
|
- lib/searchlogic/core_ext/object.rb
|
45
45
|
- lib/searchlogic/core_ext/proc.rb
|
46
46
|
- lib/searchlogic/named_scopes/alias_scope.rb
|
47
|
-
- lib/searchlogic/named_scopes/
|
47
|
+
- lib/searchlogic/named_scopes/association_conditions.rb
|
48
|
+
- lib/searchlogic/named_scopes/association_ordering.rb
|
48
49
|
- lib/searchlogic/named_scopes/conditions.rb
|
49
50
|
- lib/searchlogic/named_scopes/ordering.rb
|
50
51
|
- lib/searchlogic/rails_helpers.rb
|
@@ -54,7 +55,8 @@ files:
|
|
54
55
|
- spec/core_ext/object_spec.rb
|
55
56
|
- spec/core_ext/proc_spec.rb
|
56
57
|
- spec/named_scopes/alias_scope_spec.rb
|
57
|
-
- spec/named_scopes/
|
58
|
+
- spec/named_scopes/association_conditions_spec.rb
|
59
|
+
- spec/named_scopes/association_ordering_spec.rb
|
58
60
|
- spec/named_scopes/conditions_spec.rb
|
59
61
|
- spec/named_scopes/ordering_spec.rb
|
60
62
|
- spec/search_spec.rb
|
@@ -89,7 +91,8 @@ test_files:
|
|
89
91
|
- spec/core_ext/object_spec.rb
|
90
92
|
- spec/core_ext/proc_spec.rb
|
91
93
|
- spec/named_scopes/alias_scope_spec.rb
|
92
|
-
- spec/named_scopes/
|
94
|
+
- spec/named_scopes/association_conditions_spec.rb
|
95
|
+
- spec/named_scopes/association_ordering_spec.rb
|
93
96
|
- spec/named_scopes/conditions_spec.rb
|
94
97
|
- spec/named_scopes/ordering_spec.rb
|
95
98
|
- spec/search_spec.rb
|