Class: CarrierWave::FileCardUploader

Inherits:
Uploader::Base
  • Object
show all
Includes:
Card::Env::Location, Path
Defined in:
lib/carrier_wave/file_card_uploader.rb,
lib/carrier_wave/file_card_uploader/path.rb

Overview

custom uploader class for cards

Direct Known Subclasses

ImageCardUploader

Defined Under Namespace

Modules: Path

Constant Summary collapse

STORAGE_TYPES =
%i[cloud web coded local].freeze
CONFIG_OPTIONS =
%i[provider attributes directory public credentials
authenticated_url_expiration use_ssl_for_aws].freeze
CONFIG_CREDENTIAL_OPTIONS =
%i[
  provider
  aws_access_key_id aws_secret_access_key region host endpoint
  google_access_key_id google_secret_access_key
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Path

#cache_dir, #local_url, #local_url_base, #path, #public_path, #retrieve_path, #store_path, #tmp_path

Instance Attribute Details

#modObject

Returns the value of attribute mod.



128
129
130
# File 'lib/carrier_wave/file_card_uploader.rb', line 128

def mod
  @mod
end

Instance Method Details

#action_idObject



202
203
204
205
206
# File 'lib/carrier_wave/file_card_uploader.rb', line 202

def action_id
  model.selected_content_action_id ||
    model.last_content_action_id ||
    action_id_stand_in
end

#asset_hostObject



217
218
219
# File 'lib/carrier_wave/file_card_uploader.rb', line 217

def asset_host
  bucket_config(:asset_host) || super
end

#bucket_config(option) ⇒ Object



213
214
215
# File 'lib/carrier_wave/file_card_uploader.rb', line 213

def bucket_config option
  @model.bucket_config[option]
end

#create_versions?(new_file) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/carrier_wave/file_card_uploader.rb', line 194

def create_versions? new_file
  model.create_versions? new_file
end

#db_contentObject



164
165
166
167
168
169
# File 'lib/carrier_wave/file_card_uploader.rb', line 164

def db_content
  return model.content if model.web?
  return "" unless file.present?

  "%s/%s" % [file_dir, url_filename]
end

#extensionObject



155
156
157
158
159
160
161
162
# File 'lib/carrier_wave/file_card_uploader.rb', line 155

def extension
  case
  when file&.extension.present?     then ".#{file.extension}"
  when card_content = model.content then File.extname(card_content)
  when orig = original_filename     then File.extname(orig)
  else                              ""
  end.downcase
end

#filenameObject



147
148
149
150
151
152
153
# File 'lib/carrier_wave/file_card_uploader.rb', line 147

def filename
  if model.coded?
    "#{model.attachment_name}#{extension}"
  else
    "#{action_id}#{extension}"
  end
end

#original_filenameObject



198
199
200
# File 'lib/carrier_wave/file_card_uploader.rb', line 198

def original_filename
  @original_filename ||= model.selected_action&.comment
end

#temporary_identifierObject



179
180
181
# File 'lib/carrier_wave/file_card_uploader.rb', line 179

def temporary_identifier
  db_content
end

#url(opts = {}) ⇒ Object

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :absolute (Symbol)
    • return absolute url



184
185
186
187
188
189
190
191
192
# File 'lib/carrier_wave/file_card_uploader.rb', line 184

def url opts={}
  if model.cloud?
    file&.url
  elsif model.web?
    model.content
  else
    local_url opts
  end
end

#url_filenameObject



171
172
173
174
175
176
177
# File 'lib/carrier_wave/file_card_uploader.rb', line 171

def url_filename
  if model.coded?
    "#{model.mod}#{extension}"
  else
    "#{action_id}#{extension}"
  end
end

#valid?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/carrier_wave/file_card_uploader.rb', line 143

def valid?
  extension.present?
end