serviceable 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/serviceable.rb +18 -17
- metadata +3 -2
data/README.md
CHANGED
@@ -36,3 +36,12 @@ Query Params
|
|
36
36
|
|
37
37
|
GET /posts.json?only=id,title
|
38
38
|
[{"id":1,"title","First post!"}]
|
39
|
+
|
40
|
+
GET /posts.json?include=user
|
41
|
+
[{"id":1,"title":"First Post!","body":"Feels good to be first","created_at":"20130727T16:26:00Z","user":{"id":2,"first_name":"Jim","last_name":"Walker","display_name":"Jim W."}}]
|
42
|
+
|
43
|
+
Filter Params
|
44
|
+
-------------
|
45
|
+
|
46
|
+
GET /posts.json?where[tags][label]=Pinball
|
47
|
+
returns a set of posts tagged as "Pinball"
|
data/lib/serviceable.rb
CHANGED
@@ -130,24 +130,25 @@ 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}"
|
133
134
|
for target_column in attrs.keys
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
end
|
135
|
+
if attrs[target_column].kind_of?(String)
|
136
|
+
@collection = @collection.where(assoc => { target_column => attrs[target_column] })
|
137
|
+
elsif attrs[target_column].kind_of?(Hash)
|
138
|
+
for op in attrs[target_column].keys.map(&:to_sym)
|
139
|
+
value = is_time_column?(target_column) ? Time.parse(attrs[target_column][op]) : attrs[target_column][op]
|
140
|
+
unless assoc.to_sym==object.to_s.pluralize.to_sym
|
141
|
+
@collection = @collection.includes(assoc)
|
142
|
+
end
|
143
|
+
if op==:gt
|
144
|
+
@collection = @collection.where("#{assoc}.#{target_column} > ?",value)
|
145
|
+
elsif op==:lt
|
146
|
+
@collection = @collection.where("#{assoc}.#{target_column} < ?",value)
|
147
|
+
elsif op==:in
|
148
|
+
@collection = @collection.where("#{assoc}.#{target_column} IN (?)",value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
151
152
|
end
|
152
153
|
else
|
153
154
|
@collection = @collection.includes(assoc).where(assoc => attrs)
|
metadata
CHANGED