Class: Milton::Storage::StoredFile
- Inherits:
-
Object
- Object
- Milton::Storage::StoredFile
- Defined in:
- lib/milton/storage/stored_file.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#id ⇒ Object
Returns the value of attribute id.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.adapter(type) ⇒ Object
Returns the adapter class specified by the given type (by naming convention).
- .create(filename, id, source, options) ⇒ Object
-
.sanitize_filename(filename, options) ⇒ Object
Sanitizes the given filename, removes pathnames and the special chars needed for options seperation for derivatives.
Instance Method Summary collapse
-
#clone(filename) ⇒ Object
Creates a clone of this StoredFile of the same type with the same id and options but using the given filename.
-
#initialize(filename, id, options) ⇒ StoredFile
constructor
A new instance of StoredFile.
Constructor Details
#initialize(filename, id, options) ⇒ StoredFile
Returns a new instance of StoredFile.
32 33 34 35 36 |
# File 'lib/milton/storage/stored_file.rb', line 32 def initialize(filename, id, ) self.filename = filename self.id = id self. = end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
30 31 32 |
# File 'lib/milton/storage/stored_file.rb', line 30 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
30 31 32 |
# File 'lib/milton/storage/stored_file.rb', line 30 def id @id end |
#options ⇒ Object
Returns the value of attribute options.
30 31 32 |
# File 'lib/milton/storage/stored_file.rb', line 30 def end |
Class Method Details
.adapter(type) ⇒ Object
Returns the adapter class specified by the given type (by naming convention)
Storage::StoredFile.adapter(:s3) => Storage::S3File
Storage::StoredFile.adapter(:disk) => Storage::DiskFile
25 26 27 |
# File 'lib/milton/storage/stored_file.rb', line 25 def adapter(type) "Milton::Storage::#{type.to_s.classify}File".constantize end |
.create(filename, id, source, options) ⇒ Object
13 14 15 16 17 |
# File 'lib/milton/storage/stored_file.rb', line 13 def create(filename, id, source, ) returning new(filename, id, ) do |file| file.store(source) end end |
.sanitize_filename(filename, options) ⇒ Object
Sanitizes the given filename, removes pathnames and the special chars needed for options seperation for derivatives
7 8 9 10 11 |
# File 'lib/milton/storage/stored_file.rb', line 7 def sanitize_filename(filename, ) File.basename(filename, File.extname(filename)).gsub(/^.*(\\|\/)/, ''). gsub(/[^\w]|#{Regexp.escape(options[:separator])}/, [:replacement]). strip + File.extname(filename) end |
Instance Method Details
#clone(filename) ⇒ Object
Creates a clone of this StoredFile of the same type with the same id and options but using the given filename. Doesn’t actually do any copying of the underlying file data.
41 42 43 |
# File 'lib/milton/storage/stored_file.rb', line 41 def clone(filename) self.class.new(filename, self.id, self.) end |