Class: Dato::Local::FieldType::UploadId

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, format, size, width, height, imgix_host) ⇒ UploadId

Returns a new instance of UploadId.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dato/local/field_type/upload_id.rb', line 28

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

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/dato/local/field_type/upload_id.rb', line 9

def format
  @format
end

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/dato/local/field_type/upload_id.rb', line 9

def height
  @height
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/dato/local/field_type/upload_id.rb', line 9

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/dato/local/field_type/upload_id.rb', line 9

def size
  @size
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/dato/local/field_type/upload_id.rb', line 9

def width
  @width
end

Class Method Details

.parse(upload_id, repo) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dato/local/field_type/upload_id.rb', line 11

def self.parse(upload_id, repo)
  if upload_id
    upload = repo.entities_repo.find_entity("upload", upload_id)

    if upload
      new(
        upload.path,
        upload.format,
        upload.size,
        upload.width,
        upload.height,
        repo.site.entity.imgix_host,
      )
    end
  end
end

Instance Method Details

#fileObject



44
45
46
47
48
49
50
# File 'lib/dato/local/field_type/upload_id.rb', line 44

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

#to_hash(*_args) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/dato/local/field_type/upload_id.rb', line 56

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

#url(opts = {}) ⇒ Object



52
53
54
# File 'lib/dato/local/field_type/upload_id.rb', line 52

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