rails_rad 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/controller/json_api_concern.rb +34 -0
- data/lib/rails_rad/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a86163792f274451de4432bbf78b2741127df2
|
4
|
+
data.tar.gz: feb65ca8e0780fbcccfa97676d98087410cb6f22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4507f6e26a9c5faaef48e94c59cd4f32d712df9284548044890a8fb9fd69dfcae0c2a0d9b0122a5280ddd00e596687374ef01edd558452f9e06aa67a3edff097
|
7
|
+
data.tar.gz: b9eb44549538830fc079540963258a84ef376f50610c79979635cf5b6c8975a52c7e181d5fe370aba0a68812291a82773e9f6f14779778f80bf24fe9c3e27bca
|
@@ -5,5 +5,39 @@ module Controller
|
|
5
5
|
included do
|
6
6
|
respond_to :json
|
7
7
|
end
|
8
|
+
|
9
|
+
def index
|
10
|
+
return super unless request.format == :json
|
11
|
+
@collection = load_collection
|
12
|
+
|
13
|
+
@collection = add_filter_to_scope(@collection) if (['only'] & params.keys).any?
|
14
|
+
@collection = add_includes_to_scope(@collection) if included_associations.any?
|
15
|
+
@collection = add_count_to_scope(@collection) if params[:count]
|
16
|
+
respond_to do |format|
|
17
|
+
format.json { render json: @collection, include: included_associations }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def add_filter_to_scope(scope)
|
24
|
+
scope.select(*params[:only].split(',')) if params[:only]
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_includes_to_scope(scope)
|
28
|
+
included_associations.each do |include|
|
29
|
+
scope = scope.send(:includes, include)
|
30
|
+
# scope = scope.send(:references, include)
|
31
|
+
end
|
32
|
+
scope
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_count_to_scope(scope)
|
36
|
+
scope.count
|
37
|
+
end
|
38
|
+
|
39
|
+
def included_associations
|
40
|
+
params[:includes].respond_to?(:split) ? params[:includes].split(',') : []
|
41
|
+
end
|
8
42
|
end
|
9
43
|
end
|
data/lib/rails_rad/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_rad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -113,4 +113,3 @@ signing_key:
|
|
113
113
|
specification_version: 4
|
114
114
|
summary: Rails Rapid Application Development Tools
|
115
115
|
test_files: []
|
116
|
-
has_rdoc:
|