rest_rails 1.1.5 → 1.1.9

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
  SHA256:
3
- metadata.gz: 37bef45a003d48ac892e1108b2c60943013d79deb1cac771f5f3be33969aa37f
4
- data.tar.gz: 3aa3996113d78bc65fdc167b44ec5b1287b3626a7a3eafc9c9c3707fc6d57c9f
3
+ metadata.gz: 4bbf6117c22067039afe036aba247c3f20ac9ba930e3d1140349e70aaaf67d01
4
+ data.tar.gz: 88f538adec8d1fd23e67462434fd0845b511777313e30291937c6f89910a51a1
5
5
  SHA512:
6
- metadata.gz: a950feac58f26f179c37f370887529491d7ddf8153211d5a17f20ebfca691695ba955bf2621ee2fcca4401e3248437687d40a0c8ea2bccf5e7aa697e917bb870
7
- data.tar.gz: 1132938c2b68cce52130c22cc7ec0370ba46e0def6ae29e08d2886253e1f6464ba8393599d333f945570aa412ff4fbda1253dd1a3b4a5b3c61503fa7d5ac0193
6
+ metadata.gz: 9edb560515e507117c98bab2b05d483ab0a0e9455ead8bc820a9ab6d66d608d62dd8c6e8f640e8cac4f7d3e02a2943edb8ce258136659bb999c4a8173478a254
7
+ data.tar.gz: d8758148705b26ce8d1dbcf5cce5c55d501ddc326e417b2a19c65aab8165ddf7994a32bb949de530cd307fdfc5d3185f1af14a10064df937eaf5c601c93a70b2
@@ -16,7 +16,7 @@ module RestRails
16
16
  base_query = p_hash.blank? ? @model.all : @model.where(p_hash)
17
17
 
18
18
  @objects = base_query.order(:id).limit(ppage).offset(off)
19
- @objects.map!{|x| standardize_json(x) }
19
+ @objects = @objects.map{|x| standardize_json(x) }
20
20
 
21
21
  render json: {code: 200, objects: @objects, count: @objects.count, total: @model.count}
22
22
  end
@@ -69,10 +69,12 @@ module RestRails
69
69
  end
70
70
 
71
71
  def nested_attributes_for(ar_object)
72
- tables = ar_object.class.nested_attributes_options.keys
72
+ ar_model = ar_object.class
73
+ tables = ar_model.nested_attributes_options.keys
73
74
 
74
75
  tables.map do |x|
75
- cols = x.to_s.classify.constantize.column_names.map(&:to_sym)
76
+ nested_model = ar_model.reflect_on_association(x).klass
77
+ cols = nested_model.column_names.map(&:to_sym)
76
78
  key = "#{x}_attributes".to_sym
77
79
  cols << :_destroy
78
80
 
@@ -80,18 +82,14 @@ module RestRails
80
82
  end
81
83
  end
82
84
 
83
-
84
-
85
85
  # ==========================================================================
86
86
  # OTHER HELPERS
87
87
  # ==========================================================================
88
88
 
89
89
  def model_for(table_name)
90
- ignored = ["active_storage_blobs", "active_storage_attachments",
91
- "schema_migrations", "ar_internal_metadata"]
92
- tables = ActiveRecord::Base.connection.tables.reject{ |x| ignored.include?(x) }
90
+ tables = ActiveRecord::Base.descendants.reject(&:abstract_class).index_by(&:table_name)
93
91
 
94
- raise RestRails::Error.new "Table '#{table_name}' does not exist in your database!" unless tables.include?(table_name)
92
+ raise RestRails::Error.new "Table '#{table_name}' does not exist in your database!" unless tables.keys.include?(table_name)
95
93
 
96
94
  # Take the tablename, and make the Model of the relative table_name
97
95
  table_name.classify.constantize # "users" => User
data/config/routes.rb CHANGED
@@ -4,6 +4,7 @@ RestRails::Engine.routes.draw do
4
4
 
5
5
  get '/:table_name/:id' => 'data#show', as: 'data_show'
6
6
  patch '/:table_name/:id' => 'data#update'
7
+ put '/:table_name/:id' => 'data#update'
7
8
  delete '/:table_name/:id' => 'data#destroy', as: 'data_destroy'
8
9
 
9
10
  post '/:table_name/:id/attach/:attachment_name' => 'data#attach'
@@ -1,3 +1,3 @@
1
1
  module RestRails
2
- VERSION = '1.1.5'
2
+ VERSION = '1.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Rivas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2021-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails