rest_rails 0.9.0 → 1.0.5

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: 652e20dd610f1f6647f5d4dadac3d16a6d782bc0dc9765993d8bd064eb571e4e
4
- data.tar.gz: 4fcfb8bef731b3e1067f033d1d62eee2f31478e7f737673cc1100d222f491a69
3
+ metadata.gz: e44dc67a7765b180d91f76fb2c06adce63351171b59f5e9e9d9fff357a3ea8ce
4
+ data.tar.gz: cd7e5c02ad8e51b67cdf62a710ba7cc61c3f2c0d8e4d39f0a73932efe9d124fd
5
5
  SHA512:
6
- metadata.gz: 8427c35cfdf814c694802321f3d4b8f808f38ba8cd1b92957cc70102d1c4b56331237688213d2348fbed2c712667162091b28a558e17fee28f103b02efeeb6e9
7
- data.tar.gz: 2740b7604869ed36bf0fc594e385412b33c5bb4e3b4517cd69daba52f6fb40dc4fa63acc27409dd2b4f5fa30034978abb774fdaa922087aa01f8aa4c85112dfb
6
+ metadata.gz: 23b0e8395ce42d7046cdf727331e394a4025f64db4ad2471f8aa405f74fb136ff2bb89f6a55735f049ff50e375a0f4c5a1fbcf8f8a83020b084f62b066de900e
7
+ data.tar.gz: db74177843f17a46787af716af6cfc5514ed743b1020fa6fafe2c58adbff6f82d957595b0c1fc85c22ca5662dfe56c12d194b266de0d004def625aa1812b9d1e
@@ -154,6 +154,7 @@ module RestRails
154
154
  end
155
155
 
156
156
  def permit_array?(attr)
157
+ return false unless attr.is_a? Symbol
157
158
  permitable_classes = [ActiveStorage::Attached::Many, Array]
158
159
  permitable_classes.include?(@empty_obj.send(attr).class)
159
160
  end
@@ -61,12 +61,27 @@ module RestRails
61
61
  table = ar_object.class.table_name.to_sym
62
62
  cols = ar_object.class.column_names.map(&:to_sym)
63
63
  cols += attachments_for(ar_object) if RestRails.active_storage_attachments
64
+ cols += nested_attributes_for(ar_object) unless ar_object.class.nested_attributes_options.blank?
64
65
 
65
66
  return cols if RestRails.permit == :all || RestRails.permit[table] == :all
66
67
 
67
68
  cols.select{|x| RestRails.permit[table].include?(x) }
68
69
  end
69
70
 
71
+ def nested_attributes_for(ar_object)
72
+ tables = ar_object.class.nested_attributes_options.keys
73
+
74
+ tables.map do |x|
75
+ cols = x.to_s.classify.constantize.column_names.map(&:to_sym)
76
+ key = "#{x}_attributes".to_sym
77
+ cols.delete(:id)
78
+
79
+ {key => cols}
80
+ end
81
+ end
82
+
83
+
84
+
70
85
  # ==========================================================================
71
86
  # OTHER HELPERS
72
87
  # ==========================================================================
@@ -12,4 +12,11 @@ module RestRails
12
12
  def self.configure
13
13
  yield self
14
14
  end
15
+
16
+ def self.path_for(ar_obj)
17
+ root_path = RestRails::Engine.mounted_path
18
+ table = ar_obj.class.table_name
19
+ return "#{root_path}/#{table}" if ar_obj.id.nil?
20
+ return "#{root_path}/#{table}/#{ar_obj.id}"
21
+ end
15
22
  end
@@ -1,3 +1,3 @@
1
1
  module RestRails
2
- VERSION = '0.9.0'
2
+ VERSION = '1.0.5'
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: 0.9.0
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Rivas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-24 00:00:00.000000000 Z
11
+ date: 2019-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails