optimism 0.3.1 → 0.3.2

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: 01a5d3eb1eeb8bc21e9a623ad9d463fef69cc06ac62ac666e037af72b601e9bd
4
- data.tar.gz: ed537ddaca81ef485091adf82b79e7bee0583c0a80fe55c9e73614f10c1308e5
3
+ metadata.gz: e9ef3c31e6d2b3a6505e1e75ccc288669585e79bac805929c958d6a34158b39f
4
+ data.tar.gz: a90c0cc4dd2ab94fc8871306b26b9d4384bc7c5311846521ee0f475ab0f8caa5
5
5
  SHA512:
6
- metadata.gz: 196cff2cf80e4dd60b696f94b06295c860b1c98bd2e16faae8980784347510335f674682ae6eb25f726e5e5d71da7af1f12ad201241f921f7705cfe0439f8211
7
- data.tar.gz: b693707d8c5ac6807b70772bce0057b85a014ddc4b5e96bf94168674616808ce3c3003d86ea0842c143d6633cec9b1c3fef139fd4a842d35fe11cd49826d1abf
6
+ metadata.gz: 192cd07601317a751e09fed5aedcf7eacfaa2efbb3a1bd9c09abb116b9d75a98700ce0e6a185ae08cc3c0a3310b544b8a769e02a83dfb94c80a8abc91c06c87e
7
+ data.tar.gz: 0373c6ed5264430d53b4c84a0361cddbe5c6e6b084b47a38b8990ea957c94d8210139b4668198ec3c8724bbd1ea709ef9a83c02432eedc3bc68e1a40f8a44d89
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optimism (0.3.0)
4
+ optimism (0.3.1)
5
5
  cable_ready (>= 4)
6
6
  rack (~> 2.0)
7
7
  rails (>= 6, >= 5.2)
@@ -57,9 +57,13 @@ module Optimism
57
57
  attributes.keys.each do |attribute|
58
58
  if attribute.ends_with?("_attributes")
59
59
  resource = attribute[0..-12]
60
- nested_models = model.send(resource.to_sym)
61
- nested_models.each_with_index do |nested, index|
62
- process_resource(nested, attributes[attribute][index.to_s], ancestry + [resource, index]) if attributes[attribute].key?(index.to_s)
60
+ association = model.send(resource.to_sym)
61
+ if association.respond_to? :each_with_index
62
+ association.each_with_index do |nested, index|
63
+ process_resource(nested, attributes[attribute][index.to_s], ancestry + [resource, index]) if attributes[attribute].key?(index.to_s)
64
+ end
65
+ else
66
+ process_resource(association, attributes[attribute], ancestry + [resource])
63
67
  end
64
68
  else
65
69
  process_attribute(model, attribute, ancestry.dup)
@@ -69,7 +73,11 @@ module Optimism
69
73
 
70
74
  def process_attribute(model, attribute, ancestry)
71
75
  resource = ancestry.shift
72
- resource += "_#{ancestry.shift}_attributes_#{ancestry.shift}" until ancestry.empty?
76
+ if ancestry.size == 1
77
+ resource += "_#{ancestry.shift}_attributes"
78
+ else
79
+ resource += "_#{ancestry.shift}_attributes_#{ancestry.shift}" until ancestry.empty?
80
+ end
73
81
  container_selector, error_selector = Optimism.container_selector.sub("RESOURCE", resource).sub("ATTRIBUTE", attribute), Optimism.error_selector.sub("RESOURCE", resource).sub("ATTRIBUTE", attribute)
74
82
  if model.errors.any? && model.errors.messages.map(&:first).include?(attribute.to_sym)
75
83
  message = "#{model.errors.full_message(attribute.to_sym, model.errors.messages[attribute.to_sym].first)}#{Optimism.suffix}"
@@ -1,3 +1,3 @@
1
1
  module Optimism
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimism
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - leastbad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler