effective_resources 0.8.0 → 0.8.1
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 +4 -4
- data/app/models/effective/resources/instance.rb +22 -18
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1383850485a3ad9051e04e93dd836a381b9b1f0c
|
4
|
+
data.tar.gz: e745b62f182c4ea7e7610b0b752d8cc2c5fe525e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d8afb4eb59ee8275ab211f58bc4a5fdbf67b2cfcc7fc7ff2edc068456ee7ce558f10d61f0009fd94565dc8022ee34b4d7d231d033144cf8025c9f2f1ba25e2
|
7
|
+
data.tar.gz: 059dd7b7c19f4680c9e58dc4a60ffd412697a498cf28a5104fb1b0be04a174cdb9d2a76d6121c84ae6cd9933d7a8436ee58e3ec800d0e5da0f89d3646f03203b
|
@@ -9,40 +9,44 @@ module Effective
|
|
9
9
|
@instance || klass.new
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
# called by effective_trash as defaults, and effective_logging sometimes with true or false
|
13
|
+
def instance_attributes(include_associated: true)
|
13
14
|
return {} unless instance.present?
|
14
15
|
|
15
16
|
attributes = { attributes: instance.attributes }
|
16
17
|
|
17
18
|
# Collect to_s representations of all belongs_to associations
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
if include_associated
|
20
|
+
belong_tos.each do |association|
|
21
|
+
attributes[association.name] = instance.send(association.name).to_s
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
nested_resources.each do |association|
|
25
|
+
attributes[association.name] ||= {}
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
Array(instance.send(association.name)).each_with_index do |child, index|
|
28
|
+
resource = Effective::Resource.new(child)
|
29
|
+
attributes[association.name][index] = resource.instance_attributes
|
30
|
+
end
|
28
31
|
end
|
29
|
-
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
has_ones.each do |association|
|
34
|
+
attributes[association.name] = instance.send(association.name).to_s
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
has_manys.each do |association|
|
38
|
+
attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
has_and_belongs_to_manys.each do |association|
|
42
|
+
attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
attributes.delete_if { |_, value| value.blank? }
|
44
47
|
end
|
45
48
|
|
49
|
+
# used by effective_logging
|
46
50
|
def instance_changes
|
47
51
|
return {} unless (instance.present? && instance.changes.present?)
|
48
52
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|