Class: Worochi::Item
- Inherits:
-
Object
- Object
- Worochi::Item
- Defined in:
- lib/worochi/item.rb
Overview
Instance Attribute Summary collapse
-
#content ⇒ IO
An IO object containing the content of the file being pushed.
-
#path ⇒ String
The relative path of the object from the target root directory.
Class Method Summary collapse
-
.open(origin) ⇒ Array<Item>
Takes in either a single file entry or a list of file entries and parses them into a list of Item objects.
- .open_single(entry) ⇒ Item
Instance Method Summary collapse
-
#content_type ⇒ String
Mime-type of the content.
-
#filename ⇒ String
The filename.
-
#initialize(path, content) ⇒ Item
constructor
A new instance of Item.
-
#read(*args) ⇒ String
Read from the content.
-
#rewind ⇒ 0
Rewinds the content.
-
#size ⇒ Integer
The total size of the content in bytes.
Constructor Details
#initialize(path, content) ⇒ Item
Returns a new instance of Item.
28 29 30 31 32 33 |
# File 'lib/worochi/item.rb', line 28 def initialize(path, content) @path = path @content = content detect_type @content.rewind end |
Instance Attribute Details
#content ⇒ IO
An IO object containing the content of the file being pushed.
24 25 26 |
# File 'lib/worochi/item.rb', line 24 def content @content end |
#path ⇒ String
The relative path of the object from the target root directory. If the Worochi::Item was initialized without a ‘:path` option, this attribute defaults to the file name.
20 21 22 |
# File 'lib/worochi/item.rb', line 20 def path @path end |
Class Method Details
.open(origin) ⇒ Array<Item>
Takes in either a single file entry or a list of file entries and parses them into a list of Worochi::Item objects. Each entry can be either a String specifying the source location of the file, or a Hash specifying both the ‘:source` location and the remote `:path` to push the file to.
117 118 119 120 |
# File 'lib/worochi/item.rb', line 117 def open(origin) file_list = origin.kind_of?(Array) ? origin : [origin] file_list.map { |entry| open_single(entry) } end |
.open_single(entry) ⇒ Item
Takes in a single entry from open and creates an Worochi::Item.
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/worochi/item.rb', line 126 def open_single(entry) if entry.kind_of?(Hash) source = entry[:source] || entry['source'] path = entry[:path] || entry['path'] else source = entry end Item.new(path || File.basename(source), retrieve(source)) end |
Instance Method Details
#content_type ⇒ String
Returns mime-type of the content.
64 65 66 |
# File 'lib/worochi/item.rb', line 64 def content_type @type end |
#filename ⇒ String
Returns the filename.
36 37 38 |
# File 'lib/worochi/item.rb', line 36 def filename File.basename(path) end |
#read(*args) ⇒ String
Read from the content. This is just a wrapper for the ‘#read` method on #content and any arguments will be passed on to the IO object.
51 52 53 |
# File 'lib/worochi/item.rb', line 51 def read(*args) content.read(*args) end |
#rewind ⇒ 0
Rewinds the content. This is just a wrapper for the ‘#rewind` method on #content.
59 60 61 |
# File 'lib/worochi/item.rb', line 59 def rewind content.rewind end |
#size ⇒ Integer
The total size of the content in bytes.
43 44 45 |
# File 'lib/worochi/item.rb', line 43 def size content.size end |