Module: AbideDevUtils::Output
- Defined in:
- lib/abide_dev_utils/output.rb
Constant Summary collapse
- FWRITER =
AbideDevUtils::Files::Writer.new
Class Method Summary collapse
- .json(in_obj, console: false, file: nil, pretty: true) ⇒ Object
- .progress(title: 'Progress', start: 0, total: 100) ⇒ Object
- .simple(msg, stream: $stdout) ⇒ Object
- .yaml(in_obj, console: false, file: nil) ⇒ Object
- .yml(in_obj, console: false, file: nil) ⇒ Object
Class Method Details
.json(in_obj, console: false, file: nil, pretty: true) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/abide_dev_utils/output.rb', line 17 def self.json(in_obj, console: false, file: nil, pretty: true) AbideDevUtils::Validate.hashable(in_obj) json_out = pretty ? JSON.pretty_generate(in_obj) : JSON.generate(in_obj) simple(json_out) if console FWRITER.write_json(json_out, file: file) unless file.nil? end |
.progress(title: 'Progress', start: 0, total: 100) ⇒ Object
44 45 46 |
# File 'lib/abide_dev_utils/output.rb', line 44 def self.progress(title: 'Progress', start: 0, total: 100) ProgressBar.create(title: title, starting_at: start, total: total) end |
.simple(msg, stream: $stdout) ⇒ Object
13 14 15 |
# File 'lib/abide_dev_utils/output.rb', line 13 def self.simple(msg, stream: $stdout) stream.puts msg end |
.yaml(in_obj, console: false, file: nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/abide_dev_utils/output.rb', line 24 def self.yaml(in_obj, console: false, file: nil) yaml_out = if in_obj.is_a? String in_obj else AbideDevUtils::Validate.hashable(in_obj) # Use object's #to_yaml method if it exists, convert to hash if not in_obj.respond_to?(:to_yaml) ? in_obj.to_yaml : in_obj.to_h.to_yaml end simple(yaml_out) if console FWRITER.write_yaml(yaml_out, file: file) unless file.nil? end |
.yml(in_obj, console: false, file: nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/abide_dev_utils/output.rb', line 36 def self.yml(in_obj, console: false, file: nil) AbideDevUtils::Validate.hashable(in_obj) # Use object's #to_yaml method if it exists, convert to hash if not yml_out = in_obj.respond_to?(:to_yaml) ? in_obj.to_yaml : in_obj.to_h.to_yaml simple(yml_out) if console FWRITER.write_yml(yml_out, file: file) unless file.nil? end |