Class: Locomotive::Mounter::Models::ContentAsset

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/models/content_asset.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#_id, #created_at, #mounting_point, #updated_at

Instance Method Summary collapse

Methods inherited from Base

#initialize, #persisted?

Methods included from Fields

#[], #attributes, #attributes_with_translations, #initialize, #localized_field?, #to_hash, #to_yaml, #translated_in, #translated_in?, #write_attributes

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Models::Base

Instance Attribute Details

#filepathObject

other accessors ##



11
12
13
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11

def filepath
  @filepath
end

#folderObject

other accessors ##



11
12
13
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11

def folder
  @folder
end

#uriObject

other accessors ##



11
12
13
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11

def uri
  @uri
end

Instance Method Details

#contentString

Content of the asset.

Returns:

  • (String)

    The content of the asset



33
34
35
36
37
38
39
40
41
# File 'lib/locomotive/mounter/models/content_asset.rb', line 33

def content
  return @raw if @raw

  if self.uri
    @raw = HTTParty.get(self.uri.to_s).body
  else
    @raw = File.read(self.filepath)
  end
end

#exists?Boolean

Return true if the uri or the file exists.

Returns:

  • (Boolean)

    True if it exists



55
56
57
58
59
60
# File 'lib/locomotive/mounter/models/content_asset.rb', line 55

def exists?
  self.size
  true
rescue
  false
end

#filenameString

Name of the file

Returns:

  • (String)

    Name of the file



19
20
21
22
23
24
25
26
27
# File 'lib/locomotive/mounter/models/content_asset.rb', line 19

def filename
  return @filename if @filename

  if self.uri
    @filename = File.basename(self.uri.path)
  else
    @filename = File.basename(self.filepath)
  end
end

#local_filepathObject



62
63
64
# File 'lib/locomotive/mounter/models/content_asset.rb', line 62

def local_filepath
  File.join('/', self.folder, self.filename)
end

#sizeObject



43
44
45
46
47
48
49
# File 'lib/locomotive/mounter/models/content_asset.rb', line 43

def size
  if self.uri
    self.content.size
  else
    File.size(self.filepath)
  end
end

#sourceObject

fields ##



8
# File 'lib/locomotive/mounter/models/content_asset.rb', line 8

field :source

#to_paramsHash

Return the params used for the API.

Returns:

  • (Hash)

    The params



70
71
72
73
74
# File 'lib/locomotive/mounter/models/content_asset.rb', line 70

def to_params
  return {} if self.uri

  { source: File.new(self.filepath) }
end

#to_sObject



76
77
78
# File 'lib/locomotive/mounter/models/content_asset.rb', line 76

def to_s
  self.uri ? self.uri.path : self.filename
end