serviceable 0.4.1 → 0.4.2
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/lib/serviceable.rb +14 -4
- metadata +3 -3
data/lib/serviceable.rb
CHANGED
@@ -118,7 +118,7 @@ module Serviceable
|
|
118
118
|
# where[tags][id][in]=123,234,345 (OR)
|
119
119
|
# where[tags][id]=123&where[tags][id]=234 (AND)
|
120
120
|
define_method("assign_collection") do
|
121
|
-
@collection = object.to_s.camelize.constantize
|
121
|
+
@collection = object.to_s.camelize.constantize.scoped
|
122
122
|
if params[:include].kind_of?(Hash)
|
123
123
|
for assoc in params[:include].keys
|
124
124
|
@collection = @collection.includes(assoc.to_sym)
|
@@ -130,10 +130,15 @@ module Serviceable
|
|
130
130
|
for assoc in (params[:where].keys rescue [])
|
131
131
|
attrs = params[:where][assoc]
|
132
132
|
if attrs.kind_of?(Hash)
|
133
|
-
puts "keys: #{attrs.keys}"
|
134
133
|
for target_column in attrs.keys
|
135
134
|
if attrs[target_column].kind_of?(String)
|
136
|
-
|
135
|
+
if is_boolean_column?(target_column)
|
136
|
+
value = true if ['t','true','1','y','yes'].include?(attrs[target_column].to_s)
|
137
|
+
value = false if ['f','false','0','n','no'].include?(attrs[target_column].to_s)
|
138
|
+
else
|
139
|
+
value = attrs[target_column]
|
140
|
+
end
|
141
|
+
@collection = @collection.where(assoc => { target_column => value })
|
137
142
|
elsif attrs[target_column].kind_of?(Hash)
|
138
143
|
for op in attrs[target_column].keys.map(&:to_sym)
|
139
144
|
value = is_time_column?(target_column) ? Time.parse(attrs[target_column][op]) : attrs[target_column][op]
|
@@ -162,7 +167,12 @@ module Serviceable
|
|
162
167
|
end
|
163
168
|
|
164
169
|
define_method("is_time_column?") do |column|
|
165
|
-
|
170
|
+
object.to_s.capitalize.constantize.columns.select {|e| e.name==column.to_s}.first.type == :timestamp rescue false
|
171
|
+
# !!column[-3,3]=='_at'
|
172
|
+
end
|
173
|
+
|
174
|
+
define_method("is_boolean_column?") do |column|
|
175
|
+
object.to_s.capitalize.constantize.columns.select {|e| e.name==column.to_s}.first.type == :boolean rescue false
|
166
176
|
end
|
167
177
|
end
|
168
178
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serviceable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aubrey Goodman
|