effective_resources 1.8.33 → 1.8.37
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0717144b74cef2f8c9371376473c80c7777ed62ae65678cfa4335a32736896d7
|
4
|
+
data.tar.gz: 7c6965480ed359392c576e95ce651585a6c5c5169b50e41d5ab16c13b964cc8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31160ec3013825ae35a28359229f2fa02306776412a0fe333c5f7e2738327ad563fb525faaae64fc5db0130377ee8edc3010113514902e99a496a33d9f4701ea
|
7
|
+
data.tar.gz: ee2846f65473cd2c917c54b428cbd467531a5fa91967c8896a2b489c659c2d1250db374382f941a8af747a0e5b39c5b30be8aedf35fdee29475f133354513e1a
|
@@ -12,7 +12,13 @@ module Effective
|
|
12
12
|
@skip_to ||= skip_to_step(resource)
|
13
13
|
@redirect_to ||= resource_wizard_path(resource, @skip_to) if was_new_record
|
14
14
|
|
15
|
-
|
15
|
+
if @redirect_to
|
16
|
+
redirect_to(@redirect_to)
|
17
|
+
elsif @skip_to
|
18
|
+
redirect_to(wizard_path(@skip_to))
|
19
|
+
else
|
20
|
+
redirect_to_finish_wizard(options, params)
|
21
|
+
end
|
16
22
|
else
|
17
23
|
flash.now[:danger] = options.delete(:error) || resource_flash(:danger, resource, action)
|
18
24
|
render_step(wizard_value(step), options)
|
@@ -56,7 +56,11 @@ module Effective
|
|
56
56
|
when ActiveRecord::Relation
|
57
57
|
input.klass
|
58
58
|
when (ActiveRecord::Reflection::AbstractReflection rescue :nil)
|
59
|
-
|
59
|
+
if input.options[:polymorphic]
|
60
|
+
_klass_by_name(input.class_name)
|
61
|
+
else
|
62
|
+
(input.klass rescue nil) || _klass_by_name(input.class_name)
|
63
|
+
end
|
60
64
|
when ActiveRecord::Reflection::MacroReflection
|
61
65
|
((input.klass rescue nil).presence || _klass_by_name(input.class_name)) unless input.options[:polymorphic]
|
62
66
|
when ActionDispatch::Journey::Route
|
@@ -91,9 +91,11 @@ module Effective
|
|
91
91
|
|
92
92
|
if term == 'nil'
|
93
93
|
relation.where(is_null("#{sql_column}_id")).where(is_null("#{sql_column}_type"))
|
94
|
-
elsif type.present? && id.present?
|
94
|
+
elsif type.present? && id.present? # This was from a polymorphic select
|
95
95
|
relation.where("#{sql_column}_id = ?", id).where("#{sql_column}_type = ?", type)
|
96
|
-
|
96
|
+
elsif name == :user # Polymorphic user
|
97
|
+
relation.where(search_by_associated_conditions(association, term, fuzzy: fuzzy))
|
98
|
+
else # Maybe from a string field
|
97
99
|
id ||= Effective::Attribute.new(:integer).parse(term)
|
98
100
|
relation.where("#{sql_column}_id = ? OR #{sql_column}_type = ?", id, (type || term))
|
99
101
|
end
|
@@ -213,8 +215,10 @@ module Effective
|
|
213
215
|
|
214
216
|
# key: the id, or associated_id on my table
|
215
217
|
# keys: the ids themselves as per the target table
|
216
|
-
|
217
|
-
|
218
|
+
if association.macro == :belongs_to && association.options[:polymorphic]
|
219
|
+
key = sql_column(association.foreign_key)
|
220
|
+
keys = relation.pluck((relation.klass.primary_key rescue nil))
|
221
|
+
elsif association.macro == :belongs_to
|
218
222
|
key = sql_column(association.foreign_key)
|
219
223
|
keys = relation.pluck(association.klass.primary_key)
|
220
224
|
elsif association.macro == :has_and_belongs_to_many
|
@@ -289,7 +293,10 @@ module Effective
|
|
289
293
|
# key: the id, or associated_id on my table
|
290
294
|
# keys: the ids themselves as per the target table
|
291
295
|
|
292
|
-
if association.macro == :belongs_to
|
296
|
+
if association.macro == :belongs_to && association.options[:polymorphic]
|
297
|
+
key = sql_column(association.foreign_key)
|
298
|
+
keys = relation.pluck((relation.klass.primary_key rescue nil))
|
299
|
+
elsif association.macro == :belongs_to
|
293
300
|
key = sql_column(association.foreign_key)
|
294
301
|
keys = relation.pluck(association.klass.primary_key)
|
295
302
|
elsif association.macro == :has_and_belongs_to_many
|
data/lib/effective_resources.rb
CHANGED
@@ -64,4 +64,36 @@ module EffectiveResources
|
|
64
64
|
date.wday != 0 && date.wday != 6 && Holidays.on(date, *holidays).blank?
|
65
65
|
end
|
66
66
|
|
67
|
+
# https://stackoverflow.com/questions/66103388/attach-activestorage-blob-with-a-different-filename
|
68
|
+
def self.clone_blob(blob, options = {})
|
69
|
+
raise('expected an ActiveStorage::Blob') unless blob.kind_of?(ActiveStorage::Blob)
|
70
|
+
|
71
|
+
atts = {
|
72
|
+
filename: blob.filename,
|
73
|
+
byte_size: blob.byte_size,
|
74
|
+
checksum: blob.checksum,
|
75
|
+
content_type: blob.content_type,
|
76
|
+
metadata: blob.metadata,
|
77
|
+
}.merge(options)
|
78
|
+
|
79
|
+
service = blob.service
|
80
|
+
duplicate = ActiveStorage::Blob.create_before_direct_upload!(**atts)
|
81
|
+
|
82
|
+
case service.class.name
|
83
|
+
when 'ActiveStorage::Service::S3Service'
|
84
|
+
bucket = service.bucket
|
85
|
+
object = bucket.object(blob.key)
|
86
|
+
object.copy_to(bucket.object(duplicate.key))
|
87
|
+
when 'ActiveStorage::Service::DiskService'
|
88
|
+
path = service.path_for(blob.key)
|
89
|
+
duplicate_path = service.path_for(duplicate.key)
|
90
|
+
FileUtils.mkdir_p(File.dirname(duplicate_path))
|
91
|
+
FileUtils.ln(path, duplicate_path) if File.exists?(path)
|
92
|
+
else
|
93
|
+
raise "unknown storage service #{service.class.name}"
|
94
|
+
end
|
95
|
+
|
96
|
+
duplicate
|
97
|
+
end
|
98
|
+
|
67
99
|
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.8.
|
4
|
+
version: 1.8.37
|
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: 2021-10-
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|