Class: Agave::Local::FieldType::File

Inherits:
Object
  • Object
show all
Defined in:
lib/agave/local/field_type/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format, size, alt, title, image_host) ⇒ File

Returns a new instance of File.



32
33
34
35
36
37
38
39
# 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

Instance Attribute Details

#altObject (readonly)

Returns the value of attribute alt.



12
13
14
# File 'lib/agave/local/field_type/file.rb', line 12

def alt
  @alt
end

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/agave/local/field_type/file.rb', line 9

def format
  @format
end

#image_hostObject (readonly)

Returns the value of attribute image_host.



13
14
15
# File 'lib/agave/local/field_type/file.rb', line 13

def image_host
  @image_host
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/agave/local/field_type/file.rb', line 8

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'lib/agave/local/field_type/file.rb', line 10

def size
  @size
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/agave/local/field_type/file.rb', line 11

def title
  @title
end

Class Method Details

.parse(upload_attributes, repo) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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

Instance Method Details

#fileObject



41
42
43
44
45
46
47
# 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) ⇒ Object



53
54
55
56
57
58
59
60
61
# 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 = {}) ⇒ Object



49
50
51
# File 'lib/agave/local/field_type/file.rb', line 49

def url(opts = {})
  file.to_url(opts)
end