rest_rails 1.1.7 → 1.1.11

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: 81948eac89af4c4791ed9dc755bef3da9c247f131ba516ec441b411d76192e61
4
- data.tar.gz: 1ca64d35ae1b5dbdf326b1f97e19ffadae14ebe392dbbcd36e668600c3741474
3
+ metadata.gz: 885bcfd5d0e12d383ca8bad69bbbe60ba785f1aba018fef4fe588ad6b43ee811
4
+ data.tar.gz: 0a8e41ebe5a426a1e24edbf013b48e271c87abe98bb1990b4987841fd0b90400
5
5
  SHA512:
6
- metadata.gz: 7e44cd7f9047bd5dfbc4e7b485716a7669056aa24c1da2b29e830831009010d83691d81cb71066bb997cf7989d3cc129d130b16ab60650aaf7652b13f67e3b89
7
- data.tar.gz: b2b64cd6d7f29786d74e5ab98b417aed413ff8151277f212e97f4e8fa16d0ad6204423b4447d87e75010f0925dd7eadcd8d6eec7e4c6f227e561878dd955c15a
6
+ metadata.gz: 77b71f1bef2d7a574ca91b26b2925a16806bf6e1ef39da76f648bdda2061d9f067d111d211d6c2e70353fdf3c7e12bc39119749a7535742ca176b44068b43a6d
7
+ data.tar.gz: 68c29131e3f6d95cf393929366e0a6850e24c7e60cbd695d47f7529d2b9d7d7e1f6b4c143333bcf9b3e07a592e175c14755cc6a73517a55339cbcab0992b961a
@@ -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,21 +82,18 @@ 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
+ Zeitwerk::Loader.eager_load_all
91
+ tables = ActiveRecord::Base.descendants.reject(&:abstract_class).index_by(&:table_name)
93
92
 
94
- raise RestRails::Error.new "Table '#{table_name}' does not exist in your database!" unless tables.include?(table_name)
93
+ raise RestRails::Error.new "Table '#{table_name}' does not exist in your database!" unless tables.keys.include?(table_name)
95
94
 
96
95
  # Take the tablename, and make the Model of the relative table_name
97
- table_name.classify.constantize # "users" => User
96
+ tables[table_name]
98
97
  end
99
98
 
100
99
  def verify_permitted!(table)
@@ -1,3 +1,3 @@
1
1
  module RestRails
2
- VERSION = '1.1.7'
2
+ VERSION = '1.1.11'
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.7
4
+ version: 1.1.11
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-06-20 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