Class: Dato::Local::FieldType::File
- Inherits:
-
Object
- Object
- Dato::Local::FieldType::File
- Defined in:
- lib/dato/local/field_type/file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(path, format, size, imgix_host) ⇒ File
constructor
A new instance of File.
- #to_hash(*_args) ⇒ Object
- #url(opts = {}) ⇒ Object
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
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/dato/local/field_type/file.rb', line 8 def format @format end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/dato/local/field_type/file.rb', line 8 def path @path end |
#size ⇒ Object (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
#file ⇒ Object
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 |