Class: Locomotive::Mounter::Models::ContentAsset
- Defined in:
- lib/locomotive/mounter/models/content_asset.rb
Instance Attribute Summary collapse
-
#filepath ⇒ Object
other accessors ##.
-
#folder ⇒ Object
other accessors ##.
-
#uri ⇒ Object
other accessors ##.
Attributes inherited from Base
#_id, #created_at, #mounting_point, #updated_at
Instance Method Summary collapse
-
#content ⇒ String
Content of the asset.
-
#exists? ⇒ Boolean
Return true if the uri or the file exists.
-
#filename ⇒ String
Name of the file.
- #local_filepath ⇒ Object
- #size ⇒ Object
-
#source ⇒ Object
fields ##.
-
#to_params ⇒ Hash
Return the params used for the API.
- #to_s ⇒ Object
Methods inherited from Base
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
#filepath ⇒ Object
other accessors ##
11 12 13 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11 def filepath @filepath end |
#folder ⇒ Object
other accessors ##
11 12 13 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11 def folder @folder end |
#uri ⇒ Object
other accessors ##
11 12 13 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 11 def uri @uri end |
Instance Method Details
#content ⇒ String
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.
55 56 57 58 59 60 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 55 def exists? self.size true rescue false end |
#filename ⇒ 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_filepath ⇒ Object
62 63 64 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 62 def local_filepath File.join('/', self.folder, self.filename) end |
#size ⇒ Object
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 |
#source ⇒ Object
fields ##
8 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 8 field :source |
#to_params ⇒ Hash
Return the params used for the API.
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_s ⇒ Object
76 77 78 |
# File 'lib/locomotive/mounter/models/content_asset.rb', line 76 def to_s self.uri ? self.uri.path : self.filename end |