searchlogic 1.5.9 → 1.5.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/lib/searchlogic/condition/inclusive_descendant_of.rb +1 -1
- data/lib/searchlogic/condition/tree.rb +1 -1
- data/lib/searchlogic/conditions/magic_methods.rb +18 -2
- data/lib/searchlogic/version.rb +1 -1
- data/searchlogic.gemspec +2 -2
- data/test/conditions_tests/magic_methods_test.rb +16 -5
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -7,7 +7,7 @@ module Searchlogic
|
|
7
7
|
def self.included(klass)
|
8
8
|
klass.metaclass.class_eval do
|
9
9
|
include ClassMethods
|
10
|
-
attr_accessor :added_column_equals_conditions, :added_associations
|
10
|
+
attr_accessor :added_class_level_conditions, :added_column_equals_conditions, :added_associations
|
11
11
|
end
|
12
12
|
|
13
13
|
klass.class_eval do
|
@@ -45,6 +45,7 @@ module Searchlogic
|
|
45
45
|
def initialize_with_magic_methods(*args)
|
46
46
|
add_associations!
|
47
47
|
add_column_equals_conditions!
|
48
|
+
add_class_level_conditions!
|
48
49
|
initialize_without_magic_methods(*args)
|
49
50
|
end
|
50
51
|
|
@@ -83,6 +84,21 @@ module Searchlogic
|
|
83
84
|
klass.column_names.each { |name| setup_condition(name) }
|
84
85
|
self.class.added_column_equals_conditions = true
|
85
86
|
end
|
87
|
+
|
88
|
+
def add_class_level_conditions!
|
89
|
+
return true if self.class.added_class_level_conditions
|
90
|
+
class_level_conditions = self.class.conditions.select { |condition_class| !condition_class.condition_names_for_model.blank? }
|
91
|
+
class_level_conditions.each do |condition_class|
|
92
|
+
condition_class.condition_names_for_model.each_with_index do |condition_name, index|
|
93
|
+
if index == 0
|
94
|
+
add_condition!(condition_class, condition_name)
|
95
|
+
else
|
96
|
+
add_condition_alias!(condition_name, condition_class.condition_names_for_model.first)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
self.class.added_class_level_conditions = true
|
101
|
+
end
|
86
102
|
|
87
103
|
def sanitize_method_name(name)
|
88
104
|
name.gsub("=", "").gsub(/^(and|or)_/, "")
|
@@ -209,7 +225,7 @@ module Searchlogic
|
|
209
225
|
end
|
210
226
|
|
211
227
|
def add_condition!(condition, name, options = {})
|
212
|
-
options[:column] = options[:column].name
|
228
|
+
options[:column] = options[:column].name if options[:column]
|
213
229
|
|
214
230
|
self.class.class_eval <<-"end_eval", __FILE__, __LINE__
|
215
231
|
def #{name}_object
|
data/lib/searchlogic/version.rb
CHANGED
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 = "1.5.
|
5
|
+
s.version = "1.5.10"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Johnson of Binary Logic"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-07}
|
10
10
|
s.description = %q{Object based ActiveRecord searching, ordering, pagination, and more!}
|
11
11
|
s.email = %q{bjohnson@binarylogic.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG.rdoc", "lib/searchlogic/active_record/associations.rb", "lib/searchlogic/active_record/base.rb", "lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb", "lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb", "lib/searchlogic/condition/base.rb", "lib/searchlogic/condition/begins_with.rb", "lib/searchlogic/condition/blank.rb", "lib/searchlogic/condition/child_of.rb", "lib/searchlogic/condition/descendant_of.rb", "lib/searchlogic/condition/ends_with.rb", "lib/searchlogic/condition/equals.rb", "lib/searchlogic/condition/greater_than.rb", "lib/searchlogic/condition/greater_than_or_equal_to.rb", "lib/searchlogic/condition/inclusive_descendant_of.rb", "lib/searchlogic/condition/keywords.rb", "lib/searchlogic/condition/less_than.rb", "lib/searchlogic/condition/less_than_or_equal_to.rb", "lib/searchlogic/condition/like.rb", "lib/searchlogic/condition/nil.rb", "lib/searchlogic/condition/not_begin_with.rb", "lib/searchlogic/condition/not_blank.rb", "lib/searchlogic/condition/not_end_with.rb", "lib/searchlogic/condition/not_equal.rb", "lib/searchlogic/condition/not_have_keywords.rb", "lib/searchlogic/condition/not_like.rb", "lib/searchlogic/condition/not_nil.rb", "lib/searchlogic/condition/sibling_of.rb", "lib/searchlogic/condition/tree.rb", "lib/searchlogic/conditions/any_or_all.rb", "lib/searchlogic/conditions/base.rb", "lib/searchlogic/conditions/groups.rb", "lib/searchlogic/conditions/magic_methods.rb", "lib/searchlogic/conditions/multiparameter_attributes.rb", "lib/searchlogic/conditions/protection.rb", "lib/searchlogic/config/helpers.rb", "lib/searchlogic/config/search.rb", "lib/searchlogic/config.rb", "lib/searchlogic/core_ext/hash.rb", "lib/searchlogic/core_ext/object.rb", "lib/searchlogic/helpers/control_types/link.rb", "lib/searchlogic/helpers/control_types/links.rb", "lib/searchlogic/helpers/control_types/remote_link.rb", "lib/searchlogic/helpers/control_types/remote_links.rb", "lib/searchlogic/helpers/control_types/remote_select.rb", "lib/searchlogic/helpers/control_types/select.rb", "lib/searchlogic/helpers/form.rb", "lib/searchlogic/helpers/utilities.rb", "lib/searchlogic/modifiers/absolute.rb", "lib/searchlogic/modifiers/acos.rb", "lib/searchlogic/modifiers/asin.rb", "lib/searchlogic/modifiers/atan.rb", "lib/searchlogic/modifiers/avg.rb", "lib/searchlogic/modifiers/base.rb", "lib/searchlogic/modifiers/ceil.rb", "lib/searchlogic/modifiers/char_length.rb", "lib/searchlogic/modifiers/cos.rb", "lib/searchlogic/modifiers/cot.rb", "lib/searchlogic/modifiers/count.rb", "lib/searchlogic/modifiers/day_of_month.rb", "lib/searchlogic/modifiers/day_of_week.rb", "lib/searchlogic/modifiers/day_of_year.rb", "lib/searchlogic/modifiers/degrees.rb", "lib/searchlogic/modifiers/exp.rb", "lib/searchlogic/modifiers/floor.rb", "lib/searchlogic/modifiers/hex.rb", "lib/searchlogic/modifiers/hour.rb", "lib/searchlogic/modifiers/log.rb", "lib/searchlogic/modifiers/log10.rb", "lib/searchlogic/modifiers/log2.rb", "lib/searchlogic/modifiers/lower.rb", "lib/searchlogic/modifiers/ltrim.rb", "lib/searchlogic/modifiers/md5.rb", "lib/searchlogic/modifiers/microseconds.rb", "lib/searchlogic/modifiers/milliseconds.rb", "lib/searchlogic/modifiers/minute.rb", "lib/searchlogic/modifiers/month.rb", "lib/searchlogic/modifiers/octal.rb", "lib/searchlogic/modifiers/radians.rb", "lib/searchlogic/modifiers/round.rb", "lib/searchlogic/modifiers/rtrim.rb", "lib/searchlogic/modifiers/second.rb", "lib/searchlogic/modifiers/sign.rb", "lib/searchlogic/modifiers/sin.rb", "lib/searchlogic/modifiers/square_root.rb", "lib/searchlogic/modifiers/sum.rb", "lib/searchlogic/modifiers/tan.rb", "lib/searchlogic/modifiers/trim.rb", "lib/searchlogic/modifiers/upper.rb", "lib/searchlogic/modifiers/week.rb", "lib/searchlogic/modifiers/year.rb", "lib/searchlogic/search/base.rb", "lib/searchlogic/search/conditions.rb", "lib/searchlogic/search/ordering.rb", "lib/searchlogic/search/pagination.rb", "lib/searchlogic/search/protection.rb", "lib/searchlogic/search/searching.rb", "lib/searchlogic/shared/utilities.rb", "lib/searchlogic/shared/virtual_classes.rb", "lib/searchlogic/version.rb", "lib/searchlogic.rb", "README.rdoc", "TODO.rdoc"]
|
@@ -2,6 +2,17 @@ require File.dirname(__FILE__) + '/../test_helper.rb'
|
|
2
2
|
|
3
3
|
module ConditionsTests
|
4
4
|
class MagicMethodsTest < ActiveSupport::TestCase
|
5
|
+
def test_class_level_conditions
|
6
|
+
ben = users(:ben)
|
7
|
+
drew = users(:drew)
|
8
|
+
jennifer = users(:jennifer)
|
9
|
+
tren = users(:tren)
|
10
|
+
|
11
|
+
conditions = Searchlogic::Cache::UserConditions.new
|
12
|
+
conditions.descendant_of = ben
|
13
|
+
assert_equal ["\"users\".\"id\" = ? OR \"users\".\"id\" = ? OR \"users\".\"id\" = ?", drew.id, tren.id, jennifer.id], conditions.sanitize
|
14
|
+
end
|
15
|
+
|
5
16
|
def test_virtual_columns
|
6
17
|
search = Account.new_search
|
7
18
|
conditions = search.conditions
|
@@ -15,10 +26,10 @@ module ConditionsTests
|
|
15
26
|
assert_equal ["(strftime('%H', \"accounts\".\"created_at\") * 1) > ? AND (strftime('%w', \"accounts\".\"created_at\") * 1) <= ? AND (strftime('%m', \"accounts\".\"created_at\") * 1) IS NULL AND (strftime('%m', (strftime('%H', (strftime('%M', \"accounts\".\"created_at\") * 1)) * 1)) * 1) IS NULL", 2, 5], conditions.sanitize
|
16
27
|
assert_nothing_raised { search.all }
|
17
28
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
|
30
|
+
def test_method_conflicts
|
31
|
+
conditions = Searchlogic::Cache::AccountConditions.new
|
32
|
+
assert_nil conditions.id
|
33
|
+
end
|
23
34
|
end
|
24
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchlogic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.10
|
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: 2008-12-
|
12
|
+
date: 2008-12-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|