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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fddbfd8dcca6dad44e1b00f58681d1c8b93c95e
4
- data.tar.gz: de50132ad32654b5ff5b8505a83eb7bad8da0661
3
+ metadata.gz: 73a86163792f274451de4432bbf78b2741127df2
4
+ data.tar.gz: feb65ca8e0780fbcccfa97676d98087410cb6f22
5
5
  SHA512:
6
- metadata.gz: 863ecde808fa3121a1a407e1aaa024626f6862b57b3d8f2b8663ebf35d4d5e619f51e302cd83c3c43e6626007bf301a5b749c76a1dabcf89cf8a95fe7fc613d8
7
- data.tar.gz: 7a72d25a06c2d04f0f6916ec8a172b1e645f20931a1ff82ce20d0a5430d040a401e8f51ec2b7c9c11435e7741e39a6d005b896b5e41ec95635b3537925d3d63c
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
@@ -1,3 +1,3 @@
1
1
  module RailsRad
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
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.0.0
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-01-28 00:00:00.000000000 Z
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: