Class: Laser::Cutter::CLI::Serializer
- Inherits:
-
Object
- Object
- Laser::Cutter::CLI::Serializer
- Defined in:
- lib/laser-cutter/cli/serializer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #deserialize ⇒ Object
-
#initialize(options = {}) ⇒ Serializer
constructor
A new instance of Serializer.
- #serialize ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Serializer
Returns a new instance of Serializer.
9 10 11 |
# File 'lib/laser-cutter/cli/serializer.rb', line 9 def initialize( = {}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/laser-cutter/cli/serializer.rb', line 8 def @options end |
Instance Method Details
#deserialize ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/laser-cutter/cli/serializer.rb', line 13 def deserialize string = if .read_file.eql?('-') $stdin.read elsif File.exist?(.read_file) File.read(.read_file) end if string .replace(JSON.load(string)) end rescue Exception => e STDERR.puts "Error reading options from file #{.read_file}, #{e.}".red if .verbose STDERR.puts e.backtrace.join("\n").red end exit 1 end |
#serialize ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/laser-cutter/cli/serializer.rb', line 30 def serialize output = if .write_file.eql?('-') $stdout elsif .write_file File.open(.write_file, 'w') else nil end output.puts(JSON.pretty_generate()) output.close if output != $stdout rescue Exception => e STDERR.puts "Error writing options to file #{.write_file}, #{e.}".red if .verbose STDERR.puts e.backtrace.join("\n").red end exit 1 end |