Class: Plato::FileObject

Inherits:
Object
  • Object
show all
Defined in:
lib/plato/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (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

#pathObject (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