Class: Nochmal::Adapters::CarrierwaveAnalyze

Inherits:
Carrierwave show all
Defined in:
lib/nochmal/adapters/carrierwave_analyze.rb

Overview

Wrap ActiveStorageHelper and use carrierwave as simulated from_storage_service

Constant Summary

Constants inherited from Carrierwave

Nochmal::Adapters::Carrierwave::PREFIX

Instance Method Summary collapse

Methods inherited from Carrierwave

#blob, #collection, #models_with_attachments

Methods inherited from Base

#blob, #collection, #count, #from_storage_service, #item_completed, #list, #model_completed, #models_with_attachments, #setup, #teardown, #type_completed, #validate

Constructor Details

#initializeCarrierwaveAnalyze

rubocop:disable Metrics/ClassLength



7
8
9
10
11
12
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 7

def initialize
  super

  @carrierwave_changed = []
  @variants_present = false
end

Instance Method Details

#attachment_types_for(model) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 18

def attachment_types_for(model)
  @types[model] ||= model.uploaders.map do |uploader, uploader_class|
    @uploaders[model] = { uploader => uploader_class }
    model.has_one_attached prefixed(uploader), service: to_storage_service.name

    uploader
  end
end

#empty_collection?(_model, _uploader) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 27

def empty_collection?(_model, _uploader)
  false # simulate that uploads exist
end

#general_notesObject

hooks



39
40
41
42
43
44
45
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 39

def general_notes
  [
    display_helper_notes,
    gemfile_additions,
    final_thank_you
  ].join("\n")
end

#reupload(_record, _type) ⇒ Object

actions



33
34
35
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 33

def reupload(_record, _type)
  { status: :ok } # like count
end

#to_storage_service(to = @to) ⇒ Object



14
15
16
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 14

def to_storage_service(to = @to)
  @to_storage_service ||= ActiveStorage.new(from: :unused, to: to).to_storage_service
end

#type_notes(model = nil, type = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nochmal/adapters/carrierwave_analyze.rb', line 47

def type_notes(model = nil, type = nil)
  return nil if @carrierwave_changed.include?(model.base_class.sti_name)

  @carrierwave_changed << model.base_class.sti_name
  uploader = uploader(model, type)

  [
    carrierwave_change(model, type, uploader),
    active_storage_change(type, uploader),
    validation_notes(model, type, uploader),
    uploader_change(uploader), "\n"
  ].join
end