Class: Bulldog::Stream::Base
- Inherits:
-
Object
- Object
- Bulldog::Stream::Base
- Defined in:
- lib/bulldog/stream.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
The underlying object.
Instance Method Summary collapse
-
#content_type ⇒ Object
Return the mime-type of the content.
-
#file_name ⇒ Object
Return the original file name of the underlying object.
-
#initialize(target) ⇒ Base
constructor
A new instance of Base.
-
#missing? ⇒ Boolean
Return true if this stream represents a missing file.
-
#path ⇒ Object
Return the path of a file where the content can be found.
-
#reload ⇒ Object
Reload data from the target.
-
#size ⇒ Object
Return the size of the content.
-
#write_to(path) ⇒ Object
Write the content to the given path.
Constructor Details
#initialize(target) ⇒ Base
Returns a new instance of Base.
30 31 32 |
# File 'lib/bulldog/stream.rb', line 30 def initialize(target) @target = target end |
Instance Attribute Details
#target ⇒ Object (readonly)
The underlying object.
37 38 39 |
# File 'lib/bulldog/stream.rb', line 37 def target @target end |
Instance Method Details
#content_type ⇒ Object
Return the mime-type of the content.
77 78 79 |
# File 'lib/bulldog/stream.rb', line 77 def content_type @content_type ||= `file --brief --mime #{path}`.strip end |
#file_name ⇒ Object
Return the original file name of the underlying object. This is the basename of the file as the user uploaded it (for an uploaded file), or the file on the filesystem (for a File object). For other IO objects, return nil.
59 60 61 62 63 64 65 |
# File 'lib/bulldog/stream.rb', line 59 def file_name if @target.respond_to?(:original_path) @target.original_path else nil end end |
#missing? ⇒ Boolean
Return true if this stream represents a missing file.
49 50 51 |
# File 'lib/bulldog/stream.rb', line 49 def missing? false end |
#path ⇒ Object
Return the path of a file where the content can be found.
42 43 44 |
# File 'lib/bulldog/stream.rb', line 42 def path @target.path end |
#reload ⇒ Object
Reload data from the target.
95 96 97 |
# File 'lib/bulldog/stream.rb', line 95 def reload @content_type = nil end |
#size ⇒ Object
Return the size of the content.
70 71 72 |
# File 'lib/bulldog/stream.rb', line 70 def size File.size(path) end |
#write_to(path) ⇒ Object
Write the content to the given path.
84 85 86 87 88 89 90 |
# File 'lib/bulldog/stream.rb', line 84 def write_to(path) src, dst = self.path, path unless src == dst FileUtils.mkdir_p File.dirname(path) FileUtils.cp src, dst end end |