searchlogic 1.6.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG.rdoc +17 -0
- data/{MIT-LICENSE → LICENSE} +2 -2
- data/README.rdoc +128 -379
- data/Rakefile +56 -20
- data/VERSION.yml +4 -0
- data/init.rb +1 -1
- data/lib/searchlogic.rb +18 -98
- data/lib/searchlogic/core_ext/object.rb +33 -13
- data/lib/searchlogic/core_ext/proc.rb +11 -0
- data/lib/searchlogic/named_scopes/alias_scope.rb +63 -0
- data/lib/searchlogic/named_scopes/associations.rb +126 -0
- data/lib/searchlogic/named_scopes/conditions.rb +215 -0
- data/lib/searchlogic/named_scopes/ordering.rb +53 -0
- data/lib/searchlogic/rails_helpers.rb +69 -0
- data/lib/searchlogic/search.rb +146 -0
- data/rails/init.rb +1 -0
- data/searchlogic.gemspec +69 -0
- data/spec/core_ext/object_spec.rb +7 -0
- data/spec/core_ext/proc_spec.rb +9 -0
- data/spec/named_scopes/alias_scope_spec.rb +15 -0
- data/spec/named_scopes/associations_spec.rb +120 -0
- data/spec/named_scopes/conditions_spec.rb +253 -0
- data/spec/named_scopes/ordering_spec.rb +23 -0
- data/spec/search_spec.rb +283 -0
- data/spec/spec_helper.rb +78 -0
- metadata +40 -231
- data/Manifest.txt +0 -158
- data/TODO.rdoc +0 -4
- data/lib/searchlogic/active_record/associations.rb +0 -52
- data/lib/searchlogic/active_record/base.rb +0 -224
- data/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb +0 -176
- data/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb +0 -172
- data/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb +0 -80
- data/lib/searchlogic/condition/base.rb +0 -165
- data/lib/searchlogic/condition/begins_with.rb +0 -17
- data/lib/searchlogic/condition/blank.rb +0 -24
- data/lib/searchlogic/condition/child_of.rb +0 -11
- data/lib/searchlogic/condition/descendant_of.rb +0 -11
- data/lib/searchlogic/condition/ends_with.rb +0 -17
- data/lib/searchlogic/condition/equals.rb +0 -33
- data/lib/searchlogic/condition/greater_than.rb +0 -15
- data/lib/searchlogic/condition/greater_than_or_equal_to.rb +0 -15
- data/lib/searchlogic/condition/inclusive_descendant_of.rb +0 -10
- data/lib/searchlogic/condition/keywords.rb +0 -52
- data/lib/searchlogic/condition/less_than.rb +0 -15
- data/lib/searchlogic/condition/less_than_or_equal_to.rb +0 -15
- data/lib/searchlogic/condition/like.rb +0 -15
- data/lib/searchlogic/condition/nested_set.rb +0 -17
- data/lib/searchlogic/condition/nil.rb +0 -21
- data/lib/searchlogic/condition/not_begin_with.rb +0 -20
- data/lib/searchlogic/condition/not_blank.rb +0 -19
- data/lib/searchlogic/condition/not_end_with.rb +0 -20
- data/lib/searchlogic/condition/not_equal.rb +0 -27
- data/lib/searchlogic/condition/not_have_keywords.rb +0 -20
- data/lib/searchlogic/condition/not_like.rb +0 -20
- data/lib/searchlogic/condition/not_nil.rb +0 -19
- data/lib/searchlogic/condition/sibling_of.rb +0 -14
- data/lib/searchlogic/conditions/any_or_all.rb +0 -42
- data/lib/searchlogic/conditions/base.rb +0 -244
- data/lib/searchlogic/conditions/groups.rb +0 -74
- data/lib/searchlogic/conditions/magic_methods.rb +0 -286
- data/lib/searchlogic/conditions/multiparameter_attributes.rb +0 -105
- data/lib/searchlogic/conditions/protection.rb +0 -36
- data/lib/searchlogic/config.rb +0 -31
- data/lib/searchlogic/config/helpers.rb +0 -338
- data/lib/searchlogic/config/search.rb +0 -53
- data/lib/searchlogic/core_ext/hash.rb +0 -75
- data/lib/searchlogic/helpers/control_types/link.rb +0 -310
- data/lib/searchlogic/helpers/control_types/links.rb +0 -242
- data/lib/searchlogic/helpers/control_types/remote_link.rb +0 -87
- data/lib/searchlogic/helpers/control_types/remote_links.rb +0 -72
- data/lib/searchlogic/helpers/control_types/remote_select.rb +0 -36
- data/lib/searchlogic/helpers/control_types/select.rb +0 -82
- data/lib/searchlogic/helpers/form.rb +0 -208
- data/lib/searchlogic/helpers/utilities.rb +0 -197
- data/lib/searchlogic/modifiers/absolute.rb +0 -15
- data/lib/searchlogic/modifiers/acos.rb +0 -11
- data/lib/searchlogic/modifiers/asin.rb +0 -11
- data/lib/searchlogic/modifiers/atan.rb +0 -11
- data/lib/searchlogic/modifiers/avg.rb +0 -15
- data/lib/searchlogic/modifiers/base.rb +0 -27
- data/lib/searchlogic/modifiers/ceil.rb +0 -15
- data/lib/searchlogic/modifiers/char_length.rb +0 -15
- data/lib/searchlogic/modifiers/cos.rb +0 -15
- data/lib/searchlogic/modifiers/cot.rb +0 -15
- data/lib/searchlogic/modifiers/count.rb +0 -11
- data/lib/searchlogic/modifiers/day_of_month.rb +0 -15
- data/lib/searchlogic/modifiers/day_of_week.rb +0 -15
- data/lib/searchlogic/modifiers/day_of_year.rb +0 -15
- data/lib/searchlogic/modifiers/degrees.rb +0 -11
- data/lib/searchlogic/modifiers/exp.rb +0 -15
- data/lib/searchlogic/modifiers/floor.rb +0 -15
- data/lib/searchlogic/modifiers/hex.rb +0 -11
- data/lib/searchlogic/modifiers/hour.rb +0 -11
- data/lib/searchlogic/modifiers/log.rb +0 -15
- data/lib/searchlogic/modifiers/log10.rb +0 -11
- data/lib/searchlogic/modifiers/log2.rb +0 -11
- data/lib/searchlogic/modifiers/lower.rb +0 -15
- data/lib/searchlogic/modifiers/ltrim.rb +0 -15
- data/lib/searchlogic/modifiers/md5.rb +0 -11
- data/lib/searchlogic/modifiers/microseconds.rb +0 -11
- data/lib/searchlogic/modifiers/milliseconds.rb +0 -11
- data/lib/searchlogic/modifiers/minute.rb +0 -15
- data/lib/searchlogic/modifiers/month.rb +0 -15
- data/lib/searchlogic/modifiers/octal.rb +0 -15
- data/lib/searchlogic/modifiers/radians.rb +0 -11
- data/lib/searchlogic/modifiers/round.rb +0 -11
- data/lib/searchlogic/modifiers/rtrim.rb +0 -15
- data/lib/searchlogic/modifiers/second.rb +0 -15
- data/lib/searchlogic/modifiers/sign.rb +0 -11
- data/lib/searchlogic/modifiers/sin.rb +0 -11
- data/lib/searchlogic/modifiers/square_root.rb +0 -15
- data/lib/searchlogic/modifiers/sum.rb +0 -11
- data/lib/searchlogic/modifiers/tan.rb +0 -15
- data/lib/searchlogic/modifiers/trim.rb +0 -15
- data/lib/searchlogic/modifiers/upper.rb +0 -15
- data/lib/searchlogic/modifiers/week.rb +0 -11
- data/lib/searchlogic/modifiers/year.rb +0 -11
- data/lib/searchlogic/search/base.rb +0 -148
- data/lib/searchlogic/search/conditions.rb +0 -53
- data/lib/searchlogic/search/ordering.rb +0 -244
- data/lib/searchlogic/search/pagination.rb +0 -121
- data/lib/searchlogic/search/protection.rb +0 -89
- data/lib/searchlogic/search/searching.rb +0 -32
- data/lib/searchlogic/shared/utilities.rb +0 -57
- data/lib/searchlogic/shared/virtual_classes.rb +0 -39
- data/lib/searchlogic/version.rb +0 -79
- data/test/active_record_tests/associations_test.rb +0 -94
- data/test/active_record_tests/base_test.rb +0 -115
- data/test/condition_tests/base_test.rb +0 -62
- data/test/condition_tests/begins_with_test.rb +0 -11
- data/test/condition_tests/blank_test.rb +0 -31
- data/test/condition_tests/child_of_test.rb +0 -17
- data/test/condition_tests/descendant_of_test.rb +0 -12
- data/test/condition_tests/ends_with_test.rb +0 -11
- data/test/condition_tests/equals_test.rb +0 -28
- data/test/condition_tests/greater_than_or_equal_to_test.rb +0 -11
- data/test/condition_tests/greater_than_test.rb +0 -11
- data/test/condition_tests/inclusive_descendant_of_test.rb +0 -12
- data/test/condition_tests/keywords_test.rb +0 -23
- data/test/condition_tests/less_than_or_equal_to_test.rb +0 -11
- data/test/condition_tests/less_than_test.rb +0 -11
- data/test/condition_tests/like_test.rb +0 -11
- data/test/condition_tests/nil_test.rb +0 -31
- data/test/condition_tests/not_begin_with_test.rb +0 -8
- data/test/condition_tests/not_blank_test.rb +0 -8
- data/test/condition_tests/not_end_with_test.rb +0 -8
- data/test/condition_tests/not_equal_test.rb +0 -19
- data/test/condition_tests/not_have_keywords_test.rb +0 -8
- data/test/condition_tests/not_like_test.rb +0 -8
- data/test/condition_tests/not_nil_test.rb +0 -13
- data/test/condition_tests/sibling_of_test.rb +0 -15
- data/test/conditions_tests/any_or_all_test.rb +0 -23
- data/test/conditions_tests/base_test.rb +0 -185
- data/test/conditions_tests/groups_test.rb +0 -68
- data/test/conditions_tests/magic_methods_test.rb +0 -36
- data/test/conditions_tests/multiparameter_attributes_test.rb +0 -15
- data/test/conditions_tests/protection_test.rb +0 -18
- data/test/config_test.rb +0 -23
- data/test/fixtures/accounts.yml +0 -12
- data/test/fixtures/animals.yml +0 -7
- data/test/fixtures/orders.yml +0 -12
- data/test/fixtures/user_groups.yml +0 -5
- data/test/fixtures/users.yml +0 -45
- data/test/libs/awesome_nested_set.rb +0 -545
- data/test/libs/awesome_nested_set/.autotest +0 -13
- data/test/libs/awesome_nested_set/compatability.rb +0 -29
- data/test/libs/awesome_nested_set/helper.rb +0 -40
- data/test/libs/awesome_nested_set/named_scope.rb +0 -140
- data/test/libs/rexml_fix.rb +0 -14
- data/test/modifier_tests/day_of_month_test.rb +0 -16
- data/test/search_tests/base_test.rb +0 -241
- data/test/search_tests/conditions_test.rb +0 -21
- data/test/search_tests/ordering_test.rb +0 -167
- data/test/search_tests/pagination_test.rb +0 -74
- data/test/search_tests/protection_test.rb +0 -26
- data/test/test_helper.rb +0 -122
@@ -1,172 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module PostgreSQLAdapter
|
5
|
-
# Datetime functions
|
6
|
-
def microseconds_sql(column_name)
|
7
|
-
"date_part('microseconds', #{column_name})"
|
8
|
-
end
|
9
|
-
|
10
|
-
def milliseconds_sql(column_name)
|
11
|
-
"date_part('milliseconds', #{column_name})"
|
12
|
-
end
|
13
|
-
|
14
|
-
def second_sql(column_name)
|
15
|
-
"date_part('second', #{column_name})"
|
16
|
-
end
|
17
|
-
|
18
|
-
def minute_sql(column_name)
|
19
|
-
"date_part('minute', #{column_name})"
|
20
|
-
end
|
21
|
-
|
22
|
-
def hour_sql(column_name)
|
23
|
-
"date_part('hour', #{column_name})"
|
24
|
-
end
|
25
|
-
|
26
|
-
def day_of_week_sql(column_name)
|
27
|
-
"(date_part('dow', #{column_name}) + 1)"
|
28
|
-
end
|
29
|
-
|
30
|
-
def day_of_month_sql(column_name)
|
31
|
-
"date_part('day', #{column_name})"
|
32
|
-
end
|
33
|
-
|
34
|
-
def day_of_year_sql(column_name)
|
35
|
-
"date_part('doy', #{column_name})"
|
36
|
-
end
|
37
|
-
|
38
|
-
def week_sql(column_name)
|
39
|
-
"date_part('week', #{column_name})"
|
40
|
-
end
|
41
|
-
|
42
|
-
def month_sql(column_name)
|
43
|
-
"date_part('month', #{column_name})"
|
44
|
-
end
|
45
|
-
|
46
|
-
def year_sql(column_name)
|
47
|
-
"date_part('year', #{column_name})"
|
48
|
-
end
|
49
|
-
|
50
|
-
# String functions
|
51
|
-
def char_length_sql(column_name)
|
52
|
-
"length(#{column_name})"
|
53
|
-
end
|
54
|
-
|
55
|
-
def lower_sql(column_name)
|
56
|
-
"lower(#{column_name})"
|
57
|
-
end
|
58
|
-
|
59
|
-
def ltrim_sql(column_name)
|
60
|
-
"ltrim(#{column_name})"
|
61
|
-
end
|
62
|
-
|
63
|
-
def md5_sql(column_name)
|
64
|
-
"md5(#{column_name})"
|
65
|
-
end
|
66
|
-
|
67
|
-
def rtrim_sql(column_name)
|
68
|
-
"rtrim(#{column_name})"
|
69
|
-
end
|
70
|
-
|
71
|
-
def trim_sql(column_name)
|
72
|
-
"trim(#{column_name})"
|
73
|
-
end
|
74
|
-
|
75
|
-
def upper_sql(column_name)
|
76
|
-
"upper(#{column_name})"
|
77
|
-
end
|
78
|
-
|
79
|
-
# Number functions
|
80
|
-
def absolute_sql(column_name)
|
81
|
-
"abs(#{column_name})"
|
82
|
-
end
|
83
|
-
|
84
|
-
def acos_sql(column_name)
|
85
|
-
"acos(#{column_name})"
|
86
|
-
end
|
87
|
-
|
88
|
-
def asin_sql(column_name)
|
89
|
-
"asin(#{column_name})"
|
90
|
-
end
|
91
|
-
|
92
|
-
def atan_sql(column_name)
|
93
|
-
"atan(#{column_name})"
|
94
|
-
end
|
95
|
-
|
96
|
-
def avg_sql(column_name)
|
97
|
-
"AVG(#{column_name})"
|
98
|
-
end
|
99
|
-
|
100
|
-
def ceil_sql(column_name)
|
101
|
-
"ceil(#{column_name})"
|
102
|
-
end
|
103
|
-
|
104
|
-
def cos_sql(column_name)
|
105
|
-
"cos(#{column_name})"
|
106
|
-
end
|
107
|
-
|
108
|
-
def cot_sql(column_name)
|
109
|
-
"cot(#{column_name})"
|
110
|
-
end
|
111
|
-
|
112
|
-
def degrees_sql(column_name)
|
113
|
-
"degrees(#{column_name})"
|
114
|
-
end
|
115
|
-
|
116
|
-
def exp_sql(column_name)
|
117
|
-
"exp(#{column_name})"
|
118
|
-
end
|
119
|
-
|
120
|
-
def floor_sql(column_name)
|
121
|
-
"floor(#{column_name})"
|
122
|
-
end
|
123
|
-
|
124
|
-
def hex_sql(column_name)
|
125
|
-
"to_hex(#{column_name})"
|
126
|
-
end
|
127
|
-
|
128
|
-
def ln_sql(column_name)
|
129
|
-
"ln(#{column_name})"
|
130
|
-
end
|
131
|
-
|
132
|
-
def log_sql(column_name)
|
133
|
-
"log(#{column_name})"
|
134
|
-
end
|
135
|
-
|
136
|
-
def log2_sql(column_name)
|
137
|
-
"log(2.0, #{column_name})"
|
138
|
-
end
|
139
|
-
|
140
|
-
def log10_sql(column_name)
|
141
|
-
"log(10.0, #{column_name})"
|
142
|
-
end
|
143
|
-
|
144
|
-
def radians_sql(column_name)
|
145
|
-
"radians(#{column_name})"
|
146
|
-
end
|
147
|
-
|
148
|
-
def round_sql(column_name)
|
149
|
-
"round(#{column_name})"
|
150
|
-
end
|
151
|
-
|
152
|
-
def sign_sql(column_name)
|
153
|
-
"sign(#{column_name})"
|
154
|
-
end
|
155
|
-
|
156
|
-
def sin_sql(column_name)
|
157
|
-
"sin(#{column_name})"
|
158
|
-
end
|
159
|
-
|
160
|
-
def square_root_sql(column_name)
|
161
|
-
"sqrt(#{column_name})"
|
162
|
-
end
|
163
|
-
|
164
|
-
def tan_sql(column_name)
|
165
|
-
"tan(#{column_name})"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module ActiveRecord
|
3
|
-
module ConnectionAdapters
|
4
|
-
module SQLiteAdapter
|
5
|
-
# Date functions
|
6
|
-
def microseconds_sql(column_name)
|
7
|
-
"((strftime('%f', #{column_name}) % 1) * 1000000)"
|
8
|
-
end
|
9
|
-
|
10
|
-
def milliseconds_sql(column_name)
|
11
|
-
"((strftime('%f', #{column_name}) % 1) * 1000)"
|
12
|
-
end
|
13
|
-
|
14
|
-
def second_sql(column_name)
|
15
|
-
"(strftime('%S', #{column_name}) * 1)"
|
16
|
-
end
|
17
|
-
|
18
|
-
def minute_sql(column_name)
|
19
|
-
"(strftime('%M', #{column_name}) * 1)"
|
20
|
-
end
|
21
|
-
|
22
|
-
def hour_sql(column_name)
|
23
|
-
"(strftime('%H', #{column_name}) * 1)"
|
24
|
-
end
|
25
|
-
|
26
|
-
def day_of_week_sql(column_name)
|
27
|
-
"(strftime('%w', #{column_name}) * 1)"
|
28
|
-
end
|
29
|
-
|
30
|
-
def day_of_month_sql(column_name)
|
31
|
-
"(strftime('%d', #{column_name}) * 1)"
|
32
|
-
end
|
33
|
-
|
34
|
-
def day_of_year_sql(column_name)
|
35
|
-
"(strftime('%j', #{column_name}) * 1)"
|
36
|
-
end
|
37
|
-
|
38
|
-
def week_sql(column_name)
|
39
|
-
"(strftime('%W', #{column_name}) * 1)"
|
40
|
-
end
|
41
|
-
|
42
|
-
def month_sql(column_name)
|
43
|
-
"(strftime('%m', #{column_name}) * 1)"
|
44
|
-
end
|
45
|
-
|
46
|
-
def year_sql(column_name)
|
47
|
-
"(strftime('%Y', #{column_name}) * 1)"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Number functions
|
51
|
-
def avg_sql(column_name)
|
52
|
-
"AVG(#{column_name})"
|
53
|
-
end
|
54
|
-
|
55
|
-
# String functions
|
56
|
-
def lower_sql(column_name)
|
57
|
-
"lower(#{column_name})"
|
58
|
-
end
|
59
|
-
|
60
|
-
def ltrim_sql(column_name)
|
61
|
-
"ltrim(#{column_name})"
|
62
|
-
end
|
63
|
-
|
64
|
-
def rtrim_sql(column_name)
|
65
|
-
"rtrim(#{column_name})"
|
66
|
-
end
|
67
|
-
|
68
|
-
def trim_sql(column_name)
|
69
|
-
"trim(#{column_name})"
|
70
|
-
end
|
71
|
-
|
72
|
-
def upper_sql(column_name)
|
73
|
-
"upper(#{column_name})"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
::ActiveRecord::ConnectionAdapters::SQLiteAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::SQLiteAdapter)
|
@@ -1,165 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module Condition # :nodoc:
|
3
|
-
# = Conditions condition
|
4
|
-
#
|
5
|
-
# The base class for creating a condition. Your custom conditions should extend this class.
|
6
|
-
# See Searchlogic::Conditions::Base.register_condition on how to write your own condition.
|
7
|
-
class Base
|
8
|
-
include Shared::Utilities
|
9
|
-
|
10
|
-
attr_accessor :column, :column_for_type_cast, :column_sql, :column_sql_format, :explicit_any, :klass, :object_name, :table_name
|
11
|
-
class_inheritable_accessor :handle_array_value, :ignore_meaningless_value, :join_arrays_with_or, :value_type
|
12
|
-
self.ignore_meaningless_value = true
|
13
|
-
|
14
|
-
class << self
|
15
|
-
# Name of the condition type inferred from the class name
|
16
|
-
def condition_type_name
|
17
|
-
name.split("::").last.underscore
|
18
|
-
end
|
19
|
-
|
20
|
-
def handle_array_value?
|
21
|
-
handle_array_value == true
|
22
|
-
end
|
23
|
-
|
24
|
-
def ignore_meaningless_value? # :nodoc:
|
25
|
-
ignore_meaningless_value == true
|
26
|
-
end
|
27
|
-
|
28
|
-
def join_arrays_with_or?
|
29
|
-
join_arrays_with_or == true
|
30
|
-
end
|
31
|
-
|
32
|
-
# Determines what to call the condition for the model
|
33
|
-
#
|
34
|
-
# Searchlogic tries to create conditions on each model. Before it does this it passes the model to this method to see what to call the condition. If the condition type doesnt want to create a condition on
|
35
|
-
# a model it will just return nil and Searchlogic will skip over it.
|
36
|
-
def condition_names_for_model
|
37
|
-
[]
|
38
|
-
end
|
39
|
-
|
40
|
-
# Same as condition_name_for_model, but for a model's column obj
|
41
|
-
def condition_names_for_column
|
42
|
-
[condition_type_name]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize(klass, options = {})
|
47
|
-
self.klass = klass
|
48
|
-
self.table_name = options[:table_name] || klass.table_name
|
49
|
-
|
50
|
-
if options[:column]
|
51
|
-
self.column = options[:column].class < ::ActiveRecord::ConnectionAdapters::Column ? options[:column] : klass.columns_hash[options[:column].to_s]
|
52
|
-
|
53
|
-
if options[:column_for_type_cast]
|
54
|
-
self.column_for_type_cast = options[:column_for_type_cast]
|
55
|
-
else
|
56
|
-
type = (!self.class.value_type.blank? && self.class.value_type.to_s) || (!options[:column_type].blank? && options[:column_type].to_s) || column.sql_type
|
57
|
-
self.column_for_type_cast = column.class.new(column.name, column.default.to_s, type, column.null)
|
58
|
-
end
|
59
|
-
|
60
|
-
self.column_sql_format = options[:column_sql_format] || "{table}.{column}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def explicit_any? # :nodoc:
|
65
|
-
explicit_any == true
|
66
|
-
end
|
67
|
-
|
68
|
-
# Substitutes string vars with table and column name. Allows us to switch the column and table on the fly and have the condition update appropriately.
|
69
|
-
# The table name could be variable depending on the condition. Take STI and more than one child model is used in the condition, the first gets the parent table name, the rest get aliases.
|
70
|
-
def column_sql
|
71
|
-
column_sql_format.gsub("{table}", quoted_table_name).gsub("{column}", quoted_column_name)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Allows nils to be meaninful values
|
75
|
-
def explicitly_set_value=(value)
|
76
|
-
@explicitly_set_value = value
|
77
|
-
end
|
78
|
-
|
79
|
-
# Need this if someone wants to actually use nil in a meaningful way
|
80
|
-
def explicitly_set_value?
|
81
|
-
@explicitly_set_value == true
|
82
|
-
end
|
83
|
-
|
84
|
-
def options
|
85
|
-
{:table_name => table_name, :column => column, :column_for_type_cast => column_for_type_cast, :column_sql_format => column_sql_format}
|
86
|
-
end
|
87
|
-
|
88
|
-
# You should refrain from overwriting this method, it performs various tasks before callign your to_conditions method, allowing you to keep to_conditions simple.
|
89
|
-
def sanitize(alt_value = nil) # :nodoc:
|
90
|
-
return if value_is_meaningless?
|
91
|
-
v = alt_value || value
|
92
|
-
if v.is_a?(Array) && !self.class.handle_array_value?
|
93
|
-
scope_condition(merge_conditions(*v.collect { |i| sanitize(i) } << {:any => self.class.join_arrays_with_or?}))
|
94
|
-
else
|
95
|
-
v = v.utc if column && v.respond_to?(:utc) && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
|
96
|
-
to_conditions(v)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# The value for the condition
|
101
|
-
def value
|
102
|
-
@casted_value ||= type_cast_value(@value)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Sets the value for the condition
|
106
|
-
def value=(v)
|
107
|
-
self.explicitly_set_value = true
|
108
|
-
@casted_value = nil
|
109
|
-
@value = v
|
110
|
-
end
|
111
|
-
|
112
|
-
def value_is_meaningless? # :nodoc:
|
113
|
-
meaningless?(@value)
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
def like_condition_name
|
118
|
-
@like_condition_name ||= klass.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
119
|
-
end
|
120
|
-
|
121
|
-
def meaningless?(v)
|
122
|
-
case v
|
123
|
-
when Array
|
124
|
-
v.each { |i| return false unless meaningless?(i) }
|
125
|
-
true
|
126
|
-
else
|
127
|
-
!explicitly_set_value? || (self.class.ignore_meaningless_value? && v != false && v.blank?)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def meaningful?(v)
|
132
|
-
!meaningless?(v)
|
133
|
-
end
|
134
|
-
|
135
|
-
def quote_column_name(column_name)
|
136
|
-
klass.connection.quote_column_name(column_name)
|
137
|
-
end
|
138
|
-
|
139
|
-
def quoted_column_name
|
140
|
-
quote_column_name(column.name)
|
141
|
-
end
|
142
|
-
|
143
|
-
def quote_table_name(table_name)
|
144
|
-
klass.connection.quote_table_name(table_name)
|
145
|
-
end
|
146
|
-
|
147
|
-
def quoted_table_name
|
148
|
-
quote_table_name(table_name)
|
149
|
-
end
|
150
|
-
|
151
|
-
def type_cast_value(v)
|
152
|
-
case v
|
153
|
-
when Array
|
154
|
-
v.collect { |i| type_cast_value(i) }.compact
|
155
|
-
else
|
156
|
-
return if meaningless?(v)
|
157
|
-
return v if !column_for_type_cast || !v.is_a?(String)
|
158
|
-
tcv = column_for_type_cast.type_cast(v)
|
159
|
-
tcv -= Time.zone.utc_offset if tcv.is_a?(Time)
|
160
|
-
tcv
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module Condition
|
3
|
-
class BeginsWith < Base
|
4
|
-
self.join_arrays_with_or = true
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def condition_names_for_column
|
8
|
-
super + ["bw", "sw", "starts_with", "start"]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_conditions(value)
|
13
|
-
["#{column_sql} LIKE ?", "#{value}%"]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Searchlogic
|
2
|
-
module Condition
|
3
|
-
class Blank < Base
|
4
|
-
self.value_type = :boolean
|
5
|
-
|
6
|
-
class << self
|
7
|
-
def condition_names_for_column
|
8
|
-
super + ["is_blank"]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_conditions(value)
|
13
|
-
case column.type
|
14
|
-
when :boolean
|
15
|
-
return "(#{column_sql} IS NULL or #{column_sql} = '' or #{column_sql} = false)" if value == true
|
16
|
-
return "(#{column_sql} IS NOT NULL and #{column_sql} != '' and #{column_sql} != false)" if value == false
|
17
|
-
else
|
18
|
-
return "(#{column_sql} IS NULL or #{column_sql} = '')" if value == true
|
19
|
-
return "(#{column_sql} IS NOT NULL and #{column_sql} != '')" if value == false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|