Class: Dato::Local::FieldType::File

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

Direct Known Subclasses

Image

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format, size, imgix_host) ⇒ File

Returns a new instance of File.



19
20
21
22
23
24
# File 'lib/dato/local/field_type/file.rb', line 19

def initialize(path, format, size, imgix_host)
  @path = path
  @format = format
  @size = size
  @imgix_host = imgix_host
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Class Method Details

.parse(value, repo) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/dato/local/field_type/file.rb', line 10

def self.parse(value, repo)
  value && new(
    value[:path],
    value[:format],
    value[:size],
    repo.site.entity.imgix_host
  )
end

Instance Method Details

#fileObject



26
27
28
29
30
31
32
# File 'lib/dato/local/field_type/file.rb', line 26

def file
  Imgix::Client.new(
    host: @imgix_host,
    secure: true,
    include_library_param: false
  ).path(path)
end

#to_hash(*_args) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/dato/local/field_type/file.rb', line 38

def to_hash(*_args)
  {
    format: format,
    size: size,
    url: url
  }
end

#url(opts = {}) ⇒ Object



34
35
36
# File 'lib/dato/local/field_type/file.rb', line 34

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