Class: Pansophy::Local::CreateFile

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/pansophy/local/create_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, body) ⇒ CreateFile

Returns a new instance of CreateFile.



6
7
8
9
# File 'lib/pansophy/local/create_file.rb', line 6

def initialize(path, body)
  @pathname = Pathname.new(path)
  @body     = body
end

Instance Method Details

#call(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/pansophy/local/create_file.rb', line 11

def call(options = {})
  prevent_overwrite! unless options[:overwrite]
  @pathname.dirname.mkpath
  ::File.open(@pathname, 'wb') do |f|
    f.write @body
  end
end