effective_resources 1.2.1 → 1.2.2
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/controllers/concerns/effective/flash_messages.rb +4 -2
- data/app/models/concerns/acts_as_archived.rb +1 -1
- data/app/models/effective/resources/controller.rb +1 -1
- data/app/models/effective/resources/instance.rb +55 -32
- 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: 75c86fb082f32358410e49243ea61b344d1e691a
|
4
|
+
data.tar.gz: 5a54eba2d20082b290fdd59fb80ed54f934cca40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 == '
|
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'
|
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
|
-
|
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).
|
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(
|
14
|
+
def instance_attributes(only: nil, except: nil)
|
15
15
|
return {} unless instance.present?
|
16
16
|
|
17
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
40
|
+
next if association.options[:through]
|
32
41
|
|
33
|
-
|
42
|
+
attributes[association.name] ||= {}
|
34
43
|
|
35
|
-
|
36
|
-
|
44
|
+
Array(instance.send(association.name)).each_with_index do |child, index|
|
45
|
+
next unless child.present?
|
37
46
|
|
38
|
-
|
39
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|