effective_resources 1.2.1 → 1.2.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
  SHA1:
3
- metadata.gz: 435122fff68bc60412b461cd4eadf1b2a1c9543c
4
- data.tar.gz: 4a5a64cc84f32cf948dfe3b69e799cfcd74b52bd
3
+ metadata.gz: 75c86fb082f32358410e49243ea61b344d1e691a
4
+ data.tar.gz: 5a54eba2d20082b290fdd59fb80ed54f934cca40
5
5
  SHA512:
6
- metadata.gz: 6675a98f388897cf2b97cd93177f8fc15927b7d85eae40ed1be4b9ac5a45e4ea767c8232994609f469daaec3b84853e0a8dd153693a71a3d78fc9c8ebbdd2b9c
7
- data.tar.gz: efc25566f103fd524994ccf0c7f1bd11578ff748311e75ea034e5ca49a15de60cfcbe0fb6080bb77f26615a368855831291076e12261bda73adb8251be788b5d
6
+ metadata.gz: ae81d6db6a9a2ee2059ba36177a93d92bafbfb2a33842f28b4c718c3c478e0a454eb474459a14e072a566c09bfb436769fe7d6e7e797dce77da2ecfccf0ce9d7
7
+ data.tar.gz: c17da71ef1ba9a6e64f65d7a5bc256f0b8ab7a0e4d1b3e08d10c0b486970a236e62f553e50300cdbb32cd83fd772ce779a9d1861c8b2b0e17832b33ba6476c7d
@@ -48,11 +48,13 @@ module Effective
48
48
  action = action.to_s.gsub('_', ' ')
49
49
  word = action.split(' ').first.to_s
50
50
 
51
- if word == 'undo'
51
+ if word == 'destroy'
52
+ 'deleted'
53
+ elsif word == 'undo'
52
54
  'undid'
53
55
  elsif word.end_with?('e')
54
56
  action.sub(word, word + 'd')
55
- elsif ['a', 'i', 'o', 'u', 'y'].include?(word[-1])
57
+ elsif ['a', 'i', 'o', 'u'].include?(word[-1])
56
58
  action
57
59
  else
58
60
  action.sub(word, word + 'ed')
@@ -86,7 +86,7 @@ module ActsAsArchived
86
86
 
87
87
  def unarchive!
88
88
  transaction do
89
- update_column(:archived, false) # Does not run validations
89
+ update!(archived: false)
90
90
  acts_as_archived_options[:cascade].each { |obj| public_send(obj).update_all(archived: false) }
91
91
  end
92
92
  end
@@ -66,7 +66,7 @@ module Effective
66
66
  # It is used by datatables
67
67
  def resource_actions
68
68
  {}.tap do |actions|
69
- (member_get_actions & crud_actions).each do |action|
69
+ (member_get_actions & crud_actions).reverse_each do |action|
70
70
  actions[action.to_s.titleize] = { action: action, default: true }
71
71
  end
72
72
 
@@ -11,61 +11,78 @@ module Effective
11
11
  end
12
12
 
13
13
  # called by effective_trash and effective_logging
14
- def instance_attributes(include_associated: true, include_nested: true)
14
+ def instance_attributes(only: nil, except: nil)
15
15
  return {} unless instance.present?
16
16
 
17
- attributes = { attributes: instance.attributes }
17
+ # Build up our only and except
18
+ only = Array(only).map(&:to_sym)
19
+ except = Array(except).map(&:to_sym) + BLACKLIST
20
+
21
+ # Simple Attributes
22
+ attributes = { attributes: instance.attributes.symbolize_keys }
23
+
24
+ attributes[:attributes] = attributes[:attributes].except(*except) if except.present?
25
+ attributes[:attributes] = attributes[:attributes].slice(*only) if only.present?
18
26
 
19
27
  # Collect to_s representations of all belongs_to associations
20
- if include_associated
21
- belong_tos.each do |association|
22
- next if BLACKLIST.include?(association.name)
23
- attributes[association.name] = instance.send(association.name).to_s
24
- end
28
+ belong_tos.each do |association|
29
+ next if except.present? && except.include?(association.name)
30
+ next unless only.blank? || only.include?(association.name)
31
+
32
+ attributes[association.name] = instance.send(association.name).to_s
25
33
  end
26
34
 
27
- if include_associated || include_nested
28
- nested_resources.each do |association|
29
- next if BLACKLIST.include?(association.name)
35
+ # Grab the instance attributes of each nested resource
36
+ nested_resources.each do |association|
37
+ next if except.present? && except.include?(association.name)
38
+ next unless only.blank? || only.include?(association.name)
30
39
 
31
- attributes[association.name] ||= {}
40
+ next if association.options[:through]
32
41
 
33
- next if association.options[:through]
42
+ attributes[association.name] ||= {}
34
43
 
35
- Array(instance.send(association.name)).each_with_index do |child, index|
36
- next unless child.present?
44
+ Array(instance.send(association.name)).each_with_index do |child, index|
45
+ next unless child.present?
37
46
 
38
- resource = Effective::Resource.new(child)
39
- attributes[association.name][index] = resource.instance_attributes(include_associated: include_associated, include_nested: include_nested)
40
- end
47
+ resource = Effective::Resource.new(child)
48
+ attributes[association.name][index] = resource.instance_attributes(only: only, except: except)
41
49
  end
42
50
  end
43
51
 
44
- if include_associated
45
- has_ones.each do |association|
46
- next if BLACKLIST.include?(association.name)
47
- attributes[association.name] = instance.send(association.name).to_s
48
- end
52
+ has_ones.each do |association|
53
+ next if except.present? && except.include?(association.name)
54
+ next unless only.blank? || only.include?(association.name)
49
55
 
50
- has_manys.each do |association|
51
- next if BLACKLIST.include?(association.name)
52
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
53
- end
56
+ attributes[association.name] = instance.send(association.name).to_s
57
+ end
54
58
 
55
- has_and_belongs_to_manys.each do |association|
56
- next if BLACKLIST.include?(association.name)
57
- attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
58
- end
59
+ has_manys.each do |association|
60
+ next if except.present? && except.include?(association.name)
61
+ next unless only.blank? || only.include?(association.name)
62
+
63
+ next if BLACKLIST.include?(association.name)
64
+ attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
65
+ end
66
+
67
+ has_and_belongs_to_manys.each do |association|
68
+ next if except.present? && except.include?(association.name)
69
+ next unless only.blank? || only.include?(association.name)
70
+
71
+ attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
59
72
  end
60
73
 
61
74
  attributes.delete_if { |_, value| value.blank? }
62
75
  end
63
76
 
64
77
  # used by effective_logging
65
- def instance_changes
78
+ def instance_changes(only: nil, except: nil)
66
79
  return {} unless (instance.present? && instance.previous_changes.present?)
67
80
 
68
- changes = instance.previous_changes.dup.delete_if do |attribute, (before, after)|
81
+ # Build up our only and except
82
+ only = Array(only).map(&:to_sym)
83
+ except = Array(except).map(&:to_sym) + BLACKLIST
84
+
85
+ changes = instance.previous_changes.symbolize_keys.delete_if do |attribute, (before, after)|
69
86
  begin
70
87
  (before.kind_of?(ActiveSupport::TimeWithZone) && after.kind_of?(ActiveSupport::TimeWithZone) && before.to_i == after.to_i) ||
71
88
  (before == nil && after == false) || (before == nil && after == ''.freeze)
@@ -74,8 +91,14 @@ module Effective
74
91
  end
75
92
  end
76
93
 
94
+ changes = changes.except(*except) if except.present?
95
+ changes = changes.slice(*only) if only.present?
96
+
77
97
  # Log to_s changes on all belongs_to associations
78
98
  belong_tos.each do |association|
99
+ next if except.present? && except.include?(association.name)
100
+ next unless only.blank? || only.include?(association.name)
101
+
79
102
  if (change = changes.delete(association.foreign_key)).present?
80
103
  changes[association.name] = [(association.klass.find_by_id(change.first) if changes.first), instance.send(association.name)]
81
104
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.2.1'.freeze
2
+ VERSION = '1.2.2'.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: 1.2.1
4
+ version: 1.2.2
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: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails