effective_resources 0.8.0 → 0.8.1

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
  SHA1:
3
- metadata.gz: 548398bd2a4c2d0b765dbe366a13792a40e2738b
4
- data.tar.gz: 0c86f9d641ce9453397ae1f85b9601f0995f45d2
3
+ metadata.gz: 1383850485a3ad9051e04e93dd836a381b9b1f0c
4
+ data.tar.gz: e745b62f182c4ea7e7610b0b752d8cc2c5fe525e
5
5
  SHA512:
6
- metadata.gz: 0d8512be42bc14efb7cbd3683ed59e5a0b8a9f5c8735c9b54c0b2864f6ea4a7932e150f861eac0371cb06e7a3c0b785b46bac565fc69349b23eb6ee11f38fded
7
- data.tar.gz: 972f967e8097e08411b32f544bda79e8fdb35508a1cb48112066769a92a5084235c5d859ac2d3113b98c60820048d11c978b7abb34d3c44191227ad8b532d887
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
- def instance_attributes
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
- belong_tos.each do |association|
19
- attributes[association.name] = instance.send(association.name).to_s
20
- end
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
- nested_resources.each do |association|
23
- attributes[association.name] ||= {}
24
+ nested_resources.each do |association|
25
+ attributes[association.name] ||= {}
24
26
 
25
- Array(instance.send(association.name)).each_with_index do |child, index|
26
- resource = Effective::Resource.new(child)
27
- attributes[association.name][index] = resource.instance_attributes
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
- has_ones.each do |association|
32
- attributes[association.name] = instance.send(association.name).to_s
33
- end
33
+ has_ones.each do |association|
34
+ attributes[association.name] = instance.send(association.name).to_s
35
+ end
34
36
 
35
- has_manys.each do |association|
36
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
37
- end
37
+ has_manys.each do |association|
38
+ attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
39
+ end
38
40
 
39
- has_and_belongs_to_manys.each do |association|
40
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
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
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.8.1'.freeze
3
3
  end
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.0
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-03-29 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails