simple_search 0.0.0 → 0.0.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/VERSION +1 -1
- data/lib/simple_search/search.rb +7 -70
- data/simple_search.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/simple_search/search.rb
CHANGED
@@ -67,76 +67,13 @@ module SimpleSearch
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def add_methods_for(model, col, association = nil)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
add_numeric_options(col.name, association)
|
78
|
-
when :date, :datetime
|
79
|
-
add_date_options(col.name, association)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def add_lookup_options(column_name, association = nil)
|
85
|
-
n = column_name
|
86
|
-
if association
|
87
|
-
model = association.class_name.constantize
|
88
|
-
meth = [association.name.to_s, n].join('_').to_sym
|
89
|
-
else
|
90
|
-
model = @model
|
91
|
-
meth = n.to_sym
|
92
|
-
end
|
93
|
-
l = model.lookup_for(n)
|
94
|
-
t = model.table_name
|
95
|
-
metaclass.instance_eval do
|
96
|
-
[meth, "#{meth}_not".to_sym].each do |m|
|
97
|
-
define_method(m) do
|
98
|
-
options[m]
|
99
|
-
end
|
100
|
-
|
101
|
-
define_method("#{m}_parameters".to_sym) do
|
102
|
-
options[m]
|
103
|
-
end
|
104
|
-
|
105
|
-
define_method("#{m}_concat".to_sym) do
|
106
|
-
options["#{m}_concat".to_sym] == 'AND' ? 'AND' : 'OR'
|
107
|
-
end
|
108
|
-
|
109
|
-
define_method("#{m}_choices".to_sym) do |*filters|
|
110
|
-
filters.flatten!
|
111
|
-
opts = filters.last.is_a?(Hash) ? filters.pop : {}
|
112
|
-
|
113
|
-
l.sort {|a,b| a[1] <=> b[1]}.map{|a| a[0]}.inject([]) do |ary, key|
|
114
|
-
if filters.blank? ||
|
115
|
-
filters.detect{|f|
|
116
|
-
f.is_a?(Regexp) ? f.match(key.to_s) : key.to_s == f.to_s
|
117
|
-
}
|
118
|
-
ary << [l[key], key]
|
119
|
-
end
|
120
|
-
ary
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
define_method("#{meth}_conditions".to_sym) do
|
126
|
-
cond = []
|
127
|
-
[*options[meth]].each do
|
128
|
-
cond << "FIND_IN_SET(?, #{t}.#{n})"
|
129
|
-
end
|
130
|
-
cond
|
131
|
-
end
|
132
|
-
|
133
|
-
define_method("#{meth}_not_conditions".to_sym) do
|
134
|
-
cond = []
|
135
|
-
[*options["#{meth}_not".to_sym]].each do
|
136
|
-
cond << "NOT FIND_IN_SET(?, #{t}.#{n})"
|
137
|
-
end
|
138
|
-
cond
|
139
|
-
end
|
70
|
+
case col.type
|
71
|
+
when :string
|
72
|
+
add_string_options(col.name, association)
|
73
|
+
when :decimal, :integer, :bigint, :float
|
74
|
+
add_numeric_options(col.name, association)
|
75
|
+
when :date, :datetime
|
76
|
+
add_date_options(col.name, association)
|
140
77
|
end
|
141
78
|
end
|
142
79
|
|
data/simple_search.gemspec
CHANGED