Class: Ppson::FileJsonWriter
- Inherits:
-
Object
- Object
- Ppson::FileJsonWriter
- Defined in:
- lib/ppjson/file_json_writer.rb
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
Instance Method Summary collapse
-
#initialize(filepath) ⇒ FileJsonWriter
constructor
A new instance of FileJsonWriter.
- #write(contents, options = {:pretty => false}) ⇒ Object
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
#filepath ⇒ Object (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, = {:pretty => false}) begin File.open(filepath, 'w') do |file| Ppjson::StreamJsonWriter.new(file).write(contents, :pretty => [:pretty]) end rescue => e Escort::Logger.error.warn("Error writing file #{filepath}") end end |