effective_resources 1.8.34 → 1.8.38

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: 3a3ce02ada5c7878e2c6fab4642ba84c4ba7dbb7fb5986c7f8bc135ea8e3258c
4
- data.tar.gz: 375b538d786b4730626c5b7fb64a522ec04c789b750b25b2d4235f4617398e46
3
+ metadata.gz: a0ef8a137a53e9e2c1aa64630dfb9e90b0ae9bf3e5da8bcbc3e2f184b3273906
4
+ data.tar.gz: a467531f9b59542bdb1703b01ee8f5839019a1e540d7b0b35ecbe690a635ab11
5
5
  SHA512:
6
- metadata.gz: 65954757632e43d089f173c0e09e421c8c6528d4aa7da4fe70c7b2f24ce0f4ee90646ec8908a778e356846643cfe9d8b924dc7af2fb800a1b4040b8876a05889
7
- data.tar.gz: a1c6e51cba33a5489746a1d0954d547f4065fc75c69a87adaae35faca338c51ba91b36788c34729af74394b5d29ceeb9532b1d6acd7b8ffae06bf1ff29374f2b
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
- redirect_to(@redirect_to || wizard_path(@skip_to))
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
- ((input.klass rescue nil).presence || _klass_by_name(input.class_name)) unless input.options[:polymorphic]
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
@@ -8,6 +8,7 @@ module EffectiveGem
8
8
 
9
9
  config_keys.each do |key|
10
10
  self.singleton_class.define_method(key) { config()[key] }
11
+ self.singleton_class.define_method("#{key}=") { |value| config()[key] = value }
11
12
  end
12
13
  end
13
14
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.34'.freeze
2
+ VERSION = '1.8.38'.freeze
3
3
  end
@@ -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.34
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-07 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails