effective_resources 1.8.32 → 1.8.36

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: d4947c3721a74b21dbbda376785836f0ee3555615d56ff0f4850525b17f49d8c
4
- data.tar.gz: c70ce7a422d7c99e0ec304955cb33d528ad9d7ab0466222e94d8ec9a958442a0
3
+ metadata.gz: 06f8572e4cacab573ff3121145f120c1844e81af1c35d57d3fa9d42ffd819338
4
+ data.tar.gz: c168aa140a18323a17132c25d16edd3fb88329738f63c1a4dcfe7d66bde6ec6d
5
5
  SHA512:
6
- metadata.gz: 690b5ebefd83b651f35e586d596ebc470c05beb4bc871e71cbc711ad331ddf004cf2a22d825c37d03d25ce5edc290c14fe00d8785b2881a6557f21edf6b34c73
7
- data.tar.gz: 0c727005edcc162ffe64c8368fd5ba95ca2ff84e5d0073f24177cf521a9540343bd82897efee8d43c09917d111a74b58e51b767c434bd4f044963fc3b4c2b3c5
6
+ metadata.gz: 5043556b5414776fd0ad50ee9a298cede2ae403da26eb6cbacc4d2ccf418c71db71c22671fc5e52f378d2a0db244dd14ee45ecbf21756edcd468d0b8b22f07f2
7
+ data.tar.gz: eb2538b9526d60153db7faa8bd37eee9080001bcf268070ba2b754333213142ec90d98ba3067cb76c643f2eff988cad395d9353bdadc0a1910ed304388626054
@@ -62,5 +62,19 @@ module Effective
62
62
  wizard_path(step, resource_name_id => param)
63
63
  end
64
64
 
65
+ private
66
+
67
+ def current_step_before?(nav_step)
68
+ index = wizard_steps.index(nav_step) || raise("step #{nav_step} not found in wizard_steps")
69
+ current = wizard_steps.index(step) || raise("current step not found in wizard_steps")
70
+ current < index
71
+ end
72
+
73
+ def current_step_after?(nav_step)
74
+ index = wizard_steps.index(nav_step) || raise("step #{nav_step} not found in wizard_steps")
75
+ current = wizard_steps.index(step) || raise("current step not found in wizard_steps")
76
+ current > index
77
+ end
78
+
65
79
  end
66
80
  end
@@ -56,7 +56,11 @@ module Effective
56
56
  when ActiveRecord::Relation
57
57
  input.klass
58
58
  when (ActiveRecord::Reflection::AbstractReflection rescue :nil)
59
- ((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
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
- else
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
- if association.macro == :belongs_to
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.32'.freeze
2
+ VERSION = '1.8.36'.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.32
4
+ version: 1.8.36
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-09-30 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails