effective_resources 1.8.34 → 1.8.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/effective/wizard_controller/save.rb +7 -1
- data/app/models/effective/resources/init.rb +5 -3
- data/app/models/effective/resources/relation.rb +4 -1
- data/lib/effective_resources/effective_gem.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- data/lib/effective_resources.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ef8a137a53e9e2c1aa64630dfb9e90b0ae9bf3e5da8bcbc3e2f184b3273906
|
4
|
+
data.tar.gz: a467531f9b59542bdb1703b01ee8f5839019a1e540d7b0b35ecbe690a635ab11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2aa7368664b69915f1323908f096ced6228b98debdddc81afabca6cd6e73fcb5cb0a2e8e3fbf216a178448b4e038729836195fea5846f1b209f8b3cccd15210
|
7
|
+
data.tar.gz: 6f3138d9e04b9bd1de179211e12b71b5b338ea8324fab434bee70d6c6fdb30a67cf70f4ad06a7b2ecc3b4d7c033c994c2c85de0971a34989014a31006fea501e
|
@@ -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)
|
@@ -55,10 +55,12 @@ module Effective
|
|
55
55
|
input
|
56
56
|
when ActiveRecord::Relation
|
57
57
|
input.klass
|
58
|
-
when (ActiveRecord::Reflection::BelongsToReflection rescue :nil)
|
59
|
-
_klass_by_name(input.class_name)
|
60
58
|
when (ActiveRecord::Reflection::AbstractReflection rescue :nil)
|
61
|
-
|
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
|
62
64
|
when ActiveRecord::Reflection::MacroReflection
|
63
65
|
((input.klass rescue nil).presence || _klass_by_name(input.class_name)) unless input.options[:polymorphic]
|
64
66
|
when ActionDispatch::Journey::Route
|
@@ -293,7 +293,10 @@ module Effective
|
|
293
293
|
# key: the id, or associated_id on my table
|
294
294
|
# keys: the ids themselves as per the target table
|
295
295
|
|
296
|
-
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
|
297
300
|
key = sql_column(association.foreign_key)
|
298
301
|
keys = relation.pluck(association.klass.primary_key)
|
299
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.38
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|