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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/optimism.rb +12 -4
- data/lib/optimism/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9ef3c31e6d2b3a6505e1e75ccc288669585e79bac805929c958d6a34158b39f
|
4
|
+
data.tar.gz: a90c0cc4dd2ab94fc8871306b26b9d4384bc7c5311846521ee0f475ab0f8caa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 192cd07601317a751e09fed5aedcf7eacfaa2efbb3a1bd9c09abb116b9d75a98700ce0e6a185ae08cc3c0a3310b544b8a769e02a83dfb94c80a8abc91c06c87e
|
7
|
+
data.tar.gz: 0373c6ed5264430d53b4c84a0361cddbe5c6e6b084b47a38b8990ea957c94d8210139b4668198ec3c8724bbd1ea709ef9a83c02432eedc3bc68e1a40f8a44d89
|
data/Gemfile.lock
CHANGED
data/lib/optimism.rb
CHANGED
@@ -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
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
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}"
|
data/lib/optimism/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|