Class: Ppson::FileJsonWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ppjson/file_json_writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ FileJsonWriter

Returns a new instance of FileJsonWriter.



5
6
7
# File 'lib/ppjson/file_json_writer.rb', line 5

def initialize(filepath)
  @filepath = filepath
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



3
4
5
# File 'lib/ppjson/file_json_writer.rb', line 3

def filepath
  @filepath
end

Instance Method Details

#write(contents, options = {:pretty => false}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/ppjson/file_json_writer.rb', line 9

def write(contents, options = {:pretty => false})
  begin
    File.open(filepath, 'w') do |file|
      Ppjson::StreamJsonWriter.new(file).write(contents, :pretty => options[:pretty])
    end
  rescue => e
    Escort::Logger.error.warn("Error writing file #{filepath}")
  end
end