rest_rails 1.1.6 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f34a3f063c923fe7ed51083edea1a342f91ba07db8ac6d5051bd4a4bc5668107
4
- data.tar.gz: 62a9a39f8dcf5df212e4f47c91f5ddb7c8dbe9cc5268c3b60206aa49ec40ae49
3
+ metadata.gz: 15427d21d0ab69d7e0c821473a2475a4ca8259c1a423e88c92d770936264ed44
4
+ data.tar.gz: 1eccff913bb3e4d706a96160799d30f9b292fb43f63df784e44a78c739161a2f
5
5
  SHA512:
6
- metadata.gz: 2bba16fa4d46018a0f80e1bff7623590969370c82255c8514ec96ce00f02578d0b3d1a1166d876d04bf3afb2e50763ad09bb354d217dd4175ab996db7f6de6a3
7
- data.tar.gz: 2d900e87b15c70444004aa41aa48fc968ceb99eff88fa3ccb686c23c2c2013b1135aa950d3d7d0e998191bd908f6cc804ecedb9152e6cb25493d1b0aa32ad1ff
6
+ metadata.gz: 414990b34dfbd2ae57760be6381926de28a4e59bc4ed30abd9e9e56a83e0168c28f76884cfa9f8acdabc55cd56b6e1aab9a535cf5239f3fa5254fda6ab54c429
7
+ data.tar.gz: 3bc09bedd290c23bcd917aada308a405e4c7e4f772faf863d6fbe506c759dd4cd870cce70521a3e5df047aea625cbd638310c51caff598d7ed664a20d736e70c
@@ -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,21 +82,17 @@ 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
- table_name.classify.constantize # "users" => User
95
+ tables[table_name]
98
96
  end
99
97
 
100
98
  def verify_permitted!(table)
@@ -1,3 +1,3 @@
1
1
  module RestRails
2
- VERSION = '1.1.6'
2
+ VERSION = '1.1.10'
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.6
4
+ version: 1.1.10
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-05-25 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