class WarpEngine::Images::HostModel
The default image adapter: the host model named by image_class_name (Image), served by the host at /api/image/:id.
Constants
- URL_PREFIX
-
The path the host serves images under.
Public Instance Methods
Source
# File lib/warp_engine/images.rb, line 39 def available?(record) return true unless record.respond_to?(:file_path) File.exist?(record.file_path.to_s) end
Returns true when the file of record exists on disk, or when the record has no file_path.
Source
# File lib/warp_engine/images.rb, line 28 def build_from_upload(upload) model.new(file_upload: upload) end
Returns a new, unsaved image record built from the uploaded file.
Source
# File lib/warp_engine/images.rb, line 33 def label_for(record) record.original_filename end
Returns the label of record in the admin: its original file name.
Source
# File lib/warp_engine/images.rb, line 18 def model model_name.to_s.constantize end
Returns the image model class. Raises NameError when it does not exist.
Source
# File lib/warp_engine/images.rb, line 13 def model_name WarpEngine.config.image_class_name end
Returns the configured image class name.
Source
# File lib/warp_engine/images.rb, line 46 def select_options model.order(:original_filename).map { |record| [ label_for(record), record.id ] } end
Returns [label, id] pairs of every image, by file name, for the admin picker.
Source
# File lib/warp_engine/images.rb, line 23 def url_for(image_id) image_id.present? ? "#{URL_PREFIX}/#{image_id}" : nil end
Returns /api/image/<image_id>, or nil for a blank id.