Class: Plato::FileObject
- Inherits:
-
Object
- Object
- Plato::FileObject
- Defined in:
- lib/plato/repo.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #read)
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ FileObject
constructor
A new instance of FileObject.
- #write_to(to_path) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ FileObject
Returns a new instance of FileObject.
8 9 10 11 |
# File 'lib/plato/repo.rb', line 8 def initialize(opts = {}) @path = opts[:path] @data = opts[:data] end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: read
Returns the value of attribute data.
6 7 8 |
# File 'lib/plato/repo.rb', line 6 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/plato/repo.rb', line 6 def path @path end |
Instance Method Details
#write_to(to_path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/plato/repo.rb', line 18 def write_to(to_path) if @data FileUtils.mkdir_p(File.dirname(to_path)) File.open(to_path, 'w') {|f| f.write(@data) } elsif @path FileUtils.mkdir_p(File.dirname(to_path)) FileUtils.cp(@path, to_path) else raise "cannot write out empty file object" end end |