class Agave::Local::FieldType::File

Attributes

alt[R]
format[R]
image_host[R]
path[R]
size[R]
title[R]

Public Class Methods

new(path, format, size, alt, title, image_host) click to toggle source
# File lib/agave/local/field_type/file.rb, line 32
def initialize(path, format, size, alt, title, image_host)
  @path = path
  @format = format
  @size = size
  @image_host = image_host
  @alt = alt
  @title = title
end
parse(upload_attributes, repo) click to toggle source
# File lib/agave/local/field_type/file.rb, line 15
def self.parse(upload_attributes, repo)
  return nil if !upload_attributes
  return nil if !upload_attributes[:path]
  upload = repo.entities_repo.find_entity(
    "upload", upload_attributes[:path]
  )
  return nil if !upload
  new(
    upload.path,
    upload.format,
    upload.size,
    upload.alt,
    upload.title,
    repo.site.entity.image_host
  )
end

Public Instance Methods

file() click to toggle source
# File lib/agave/local/field_type/file.rb, line 41
def file
  Imgix::Client.new(
    host: image_host,
    secure: true,
    include_library_param: false
  ).path(path)
end
to_hash(*_args) click to toggle source
# File lib/agave/local/field_type/file.rb, line 53
def to_hash(*_args)
  {
    format: format,
    size: size,
    alt: alt,
    title: title,
    url: url
  }
end
url(opts = {}) click to toggle source
# File lib/agave/local/field_type/file.rb, line 49
def url(opts = {})
  file.to_url(opts)
end