restpack-resource 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/restpack-resource/resource/filterable.rb +1 -1
- data/lib/restpack-resource/resource/includable.rb +1 -1
- data/lib/restpack-resource/resource/sortable.rb +1 -1
- data/lib/restpack-resource/service.rb +1 -3
- data/lib/restpack-resource/version.rb +1 -1
- data/spec/resource/resource_spec.rb +3 -2
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -7,7 +7,7 @@ module RestPack
|
|
7
7
|
@resource_includable_associations || []
|
8
8
|
end
|
9
9
|
def resource_includable_associations=(associations)
|
10
|
-
@resource_includable_associations = associations
|
10
|
+
@resource_includable_associations = associations.uniq
|
11
11
|
end
|
12
12
|
def resource_can_include(*associations)
|
13
13
|
self.resource_includable_associations += associations
|
@@ -4,7 +4,6 @@ module RestPack
|
|
4
4
|
module Service
|
5
5
|
|
6
6
|
def paged_resource(klass, params, options = {})
|
7
|
-
p "1 Params: #{params}"
|
8
7
|
options[:page] ||= params['page'].to_i if params['page']
|
9
8
|
options[:includes] ||= extract_includes_from_params(params) unless params['includes'].nil?
|
10
9
|
options[:sort_by] ||= params['sort_by'].to_sym if params['sort_by']
|
@@ -12,7 +11,7 @@ module RestPack
|
|
12
11
|
|
13
12
|
filters = extract_filters_from_params(klass, params)
|
14
13
|
options[:filters] ||= filters unless filters.empty?
|
15
|
-
|
14
|
+
|
16
15
|
klass.paged_resource(options)
|
17
16
|
end
|
18
17
|
|
@@ -27,7 +26,6 @@ module RestPack
|
|
27
26
|
|
28
27
|
def extract_filters_from_params(klass, params)
|
29
28
|
extracted = params.with_indifferent_access.extract!(*klass.resource_filterable_by)
|
30
|
-
p "2. EXTRA: #{extracted}"
|
31
29
|
extracted.delete_if { |k, v| v.nil? }
|
32
30
|
end
|
33
31
|
|
@@ -19,7 +19,7 @@ describe RestPack::Resource do
|
|
19
19
|
MyModel.resource_includable_associations.length == 0
|
20
20
|
class MyModel
|
21
21
|
resource_can_include :association1
|
22
|
-
resource_can_include :association2, :association3
|
22
|
+
resource_can_include :association2, :association3, :association3
|
23
23
|
end
|
24
24
|
MyModel.resource_includable_associations.should == [:association1, :association2, :association3]
|
25
25
|
end
|
@@ -31,6 +31,7 @@ describe RestPack::Resource do
|
|
31
31
|
class MyModel
|
32
32
|
resource_can_filter_by :id
|
33
33
|
resource_can_filter_by :name, :age
|
34
|
+
resource_can_filter_by :name, :age
|
34
35
|
end
|
35
36
|
MyModel.resource_filterable_by.should == [:id, :name, :age]
|
36
37
|
end
|
@@ -41,7 +42,7 @@ describe RestPack::Resource do
|
|
41
42
|
MyModel.resource_sortable_by.length == 0
|
42
43
|
class MyModel
|
43
44
|
resource_can_sort_by :id
|
44
|
-
resource_can_sort_by :name, :age
|
45
|
+
resource_can_sort_by :name, :age, :id
|
45
46
|
end
|
46
47
|
MyModel.resource_sortable_by.should == [:id, :name, :age]
|
47
48
|
end
|