effective_resources 2.5.4 → 2.6.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b05139233c80055128a85d5d530093dce5298a30f69bf22bf4ac52e6e8edea01
|
4
|
+
data.tar.gz: 262b94abbdef2122707827ec1b838885b13f05689d3c274eacde638bebdbffc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4a5755f86f90fd14436bbce9e4595381c7159042b4fa671171ca7c4d7a52456653e0a0acc9307f655bc3c14d840f2b188907d2266dc937fb40f807bf88b64a8
|
7
|
+
data.tar.gz: c81a56fbc58c5759239a1f6c7de59ccc3b0efe43bc1fa5a2332867602b029330a6820f8bc485566addd11abc7323f13036ae8d075b6bc1c0f027ac54e799264e
|
@@ -63,8 +63,9 @@ module ActsAsSlugged
|
|
63
63
|
slug = "#{slug}-#{self.class.name.demodulize.parameterize}"
|
64
64
|
end
|
65
65
|
|
66
|
-
if (count = self.class.where(slug
|
67
|
-
|
66
|
+
if (count = self.class.where('slug ILIKE ?', "#{slug}%").count) > 0
|
67
|
+
uid = (Time.zone.now.to_i - 1_500_000_000).to_s(36) # This is a unique 6 digit url safe string
|
68
|
+
slug = "#{slug}-#{uid}"
|
68
69
|
end
|
69
70
|
|
70
71
|
slug
|
@@ -24,67 +24,6 @@ module ActsAsStatused
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
module CanCan
|
28
|
-
# The idea here is you can go forward but you can't go back.
|
29
|
-
def acts_as_statused(klass, only: nil, except: nil)
|
30
|
-
raise "klass does not implement acts_as_statused" unless klass.acts_as_statused?
|
31
|
-
|
32
|
-
statuses = klass.const_get(:STATUSES)
|
33
|
-
instance = klass.new
|
34
|
-
|
35
|
-
only = Array(only).compact
|
36
|
-
except = Array(except).compact
|
37
|
-
|
38
|
-
statuses.each_with_index do |status, index|
|
39
|
-
action = status_active_verb(status, instance)
|
40
|
-
|
41
|
-
next if action.blank?
|
42
|
-
next if only.present? && !only.include?(action)
|
43
|
-
next if except.present? && except.include?(action)
|
44
|
-
|
45
|
-
if index == 0
|
46
|
-
can(action, klass) and next
|
47
|
-
end
|
48
|
-
|
49
|
-
if status == :approved && statuses.include?(:declined)
|
50
|
-
if (position = statuses.index { |status| (status == :approved || status == :declined) }) > 0
|
51
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[position-1]}?") || obj.declined? }
|
52
|
-
next
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
if status == :declined && statuses.include?(:approved)
|
57
|
-
if (position = statuses.index { |status| (status == :approved || status == :declined) }) > 0
|
58
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[position-1]}?") }
|
59
|
-
next
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
can(action, klass) { |obj| obj.public_send("#{statuses[index-1]}?") }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
# requested -> request, approved -> approve, declined -> decline, pending -> pending
|
70
|
-
def status_active_verb(status, instance)
|
71
|
-
status = status.to_s.strip
|
72
|
-
|
73
|
-
if status.end_with?('ied')
|
74
|
-
action = status[0...-3] + 'y'
|
75
|
-
return action.to_sym if instance.respond_to?(action + '!')
|
76
|
-
end
|
77
|
-
|
78
|
-
# ed, e, ing
|
79
|
-
[-1, -2, -3].each do |index|
|
80
|
-
action = status[0...index]
|
81
|
-
return action.to_sym if instance.respond_to?(action + '!')
|
82
|
-
end
|
83
|
-
|
84
|
-
nil
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
27
|
included do
|
89
28
|
acts_as_statused_options = @acts_as_statused_options
|
90
29
|
|
@@ -103,38 +42,85 @@ module ActsAsStatused
|
|
103
42
|
self.status ||= self.class.const_get(:STATUSES).first
|
104
43
|
|
105
44
|
# Set an existing belongs_to automatically
|
106
|
-
if respond_to?("#{status}_by
|
45
|
+
if respond_to?("#{status}_by") && send("#{status}_by").blank?
|
107
46
|
self.send("#{status}_by=", current_user)
|
108
47
|
end
|
109
48
|
|
110
49
|
# Set an existing timestamp automatically
|
111
|
-
if respond_to?("#{status}_at
|
50
|
+
if respond_to?("#{status}_at") && send("#{status}_at").blank?
|
112
51
|
self.send("#{status}_at=", Time.zone.now)
|
113
52
|
end
|
114
53
|
|
54
|
+
if current_user.present?
|
55
|
+
self.status_steps["#{status}_by_id".to_sym] ||= current_user.id
|
56
|
+
self.status_steps["#{status}_by_type".to_sym] ||= current_user.class.name
|
57
|
+
end
|
58
|
+
|
115
59
|
self.status_steps["#{status}_at".to_sym] ||= Time.zone.now
|
116
|
-
self.status_steps["#{status}_by".to_sym] ||= current_user.try(:id)
|
117
60
|
end
|
118
61
|
|
119
62
|
validates :status, presence: true, inclusion: { in: const_get(:STATUSES).map(&:to_s) }
|
120
63
|
|
121
64
|
# Create an received scope and approved? method for each status
|
122
65
|
acts_as_statused_options[:statuses].each do |sym|
|
66
|
+
sym_at = "#{sym}_at".to_sym
|
67
|
+
sym_by = "#{sym}_by".to_sym
|
68
|
+
sym_by_id = "#{sym}_by_id".to_sym
|
69
|
+
sym_by_type = "#{sym}_by_type".to_sym
|
70
|
+
|
123
71
|
scope(sym, -> { where(status: sym.to_s) })
|
124
72
|
|
73
|
+
# approved?
|
125
74
|
define_method("#{sym}?") { status == sym.to_s }
|
126
|
-
define_method("was_#{sym}?") { send("#{sym}_at").present? }
|
127
75
|
|
128
|
-
#
|
129
|
-
|
130
|
-
|
131
|
-
#
|
76
|
+
# was_approved?
|
77
|
+
define_method("was_#{sym}?") { send(sym_at).present? }
|
78
|
+
|
79
|
+
# approved_at
|
80
|
+
define_method(sym_at) { self[sym_at.to_s] || status_steps[sym_at] }
|
81
|
+
|
82
|
+
# approved_by_id
|
83
|
+
define_method(sym_by_id) { self[sym_by_id.to_s] || status_steps[sym_by_id] }
|
84
|
+
|
85
|
+
# approved_by_type
|
86
|
+
define_method(sym_by_type) { self[sym_by_type.to_s] || status_steps[sym_by_type] }
|
87
|
+
|
88
|
+
# approved_by
|
89
|
+
define_method(sym_by) do
|
90
|
+
user = (super() if attributes.key?(sym_by_id.to_s))
|
91
|
+
|
92
|
+
user ||= begin
|
93
|
+
id = status_steps[sym_by_id]
|
94
|
+
klass = status_steps[sym_by_type]
|
95
|
+
|
96
|
+
klass.constantize.find(id) if id.present? && klass.present?
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# approved_at=
|
101
|
+
define_method("#{sym_at}=") do |value|
|
102
|
+
super(value) if attributes.key?(sym_at.to_s)
|
103
|
+
status_steps[sym_at] = value
|
104
|
+
end
|
105
|
+
|
106
|
+
# approved_by_id=
|
107
|
+
define_method("#{sym_by_id}=") do |value|
|
108
|
+
super(value) if attributes.key?(sym_by_id.to_s)
|
109
|
+
status_steps[sym_by_id] = value
|
110
|
+
end
|
111
|
+
|
112
|
+
# approved_by_type=
|
113
|
+
define_method("#{sym_by_type}=") do |value|
|
114
|
+
super(value) if attributes.key?(sym_by_type.to_s)
|
115
|
+
status_steps[sym_by_type] = value
|
116
|
+
end
|
132
117
|
|
133
|
-
#
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
118
|
+
# approved_by=
|
119
|
+
define_method("#{sym_by}=") do |value|
|
120
|
+
super(value) if attributes.key?(sym_by_id.to_s)
|
121
|
+
status_steps[sym_by_id] = value&.id
|
122
|
+
status_steps[sym_by_type] = value&.class&.name
|
123
|
+
end
|
138
124
|
|
139
125
|
# approved!
|
140
126
|
define_method("#{sym}!") do |atts = {}|
|
@@ -146,17 +132,18 @@ module ActsAsStatused
|
|
146
132
|
define_method("un#{sym}!") do
|
147
133
|
self.status = nil if (status == sym.to_s)
|
148
134
|
|
149
|
-
|
150
|
-
status_steps.delete("#{sym}_by".to_sym)
|
151
|
-
|
152
|
-
if respond_to?("#{sym}_at=") && respond_to?("#{sym}_at") && send("#{sym}_at").present?
|
135
|
+
if respond_to?("#{sym}_at") && send("#{sym}_at").present?
|
153
136
|
self.send("#{sym}_at=", nil)
|
154
137
|
end
|
155
138
|
|
156
|
-
if respond_to?("#{sym}_by
|
139
|
+
if respond_to?("#{sym}_by") && send("#{sym}_by").present?
|
157
140
|
self.send("#{sym}_by=", nil)
|
158
141
|
end
|
159
142
|
|
143
|
+
status_steps.delete(sym_at)
|
144
|
+
status_steps.delete(sym_by_id)
|
145
|
+
status_steps.delete(sym_by_type)
|
146
|
+
|
160
147
|
true
|
161
148
|
end
|
162
149
|
|
@@ -167,16 +154,4 @@ module ActsAsStatused
|
|
167
154
|
def acts_as_statused?; true; end
|
168
155
|
end
|
169
156
|
|
170
|
-
private
|
171
|
-
|
172
|
-
def acts_as_statused_by_user(status)
|
173
|
-
return nil if status_steps["#{status}_by".to_sym].blank?
|
174
|
-
|
175
|
-
@acts_as_statused_by_users ||= begin
|
176
|
-
User.where(id: status_steps.map { |k, v| v.presence if k.to_s.end_with?('_by') }.compact).all.inject({}) { |h, user| h[user.id] = user; h }
|
177
|
-
end
|
178
|
-
|
179
|
-
@acts_as_statused_by_users[status_steps["#{status}_by".to_sym]]
|
180
|
-
end
|
181
|
-
|
182
157
|
end
|
@@ -281,7 +281,8 @@ module Effective
|
|
281
281
|
|
282
282
|
# Normalize the term.
|
283
283
|
# If you pass an email attribute it can return nil so we return the full value
|
284
|
-
term = Attribute.new(as).parse(value, name: name)
|
284
|
+
term = Attribute.new(as).parse(value, name: name)
|
285
|
+
term = value if term.nil?
|
285
286
|
|
286
287
|
# If using the joined syntax from datatables
|
287
288
|
joined = (sql_column.to_s.split('.').first.to_s.include?(relation.arel_table.name) == false)
|
@@ -305,7 +306,14 @@ module Effective
|
|
305
306
|
end
|
306
307
|
)
|
307
308
|
|
309
|
+
if as == :date
|
310
|
+
term = term.to_date
|
311
|
+
end_at = end_at.to_date
|
312
|
+
end
|
313
|
+
|
308
314
|
relation.where("#{sql_column} >= ? AND #{sql_column} <= ?", term, end_at)
|
315
|
+
elsif value.respond_to?(:strftime) && operation == :eq
|
316
|
+
relation.where(attribute.matches(value))
|
309
317
|
end
|
310
318
|
|
311
319
|
when :effective_obfuscation
|
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: 2.
|
4
|
+
version: 2.6.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: 2023-03-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|