Class: IParty::CLI::Formatter::JsonFormatter

Inherits:
IParty::CLI::Formatter show all
Defined in:
lib/iparty/cli/formatter.rb

Constant Summary

Constants inherited from IParty::CLI::Formatter

VOID_OUTPUT

Constants included from Colorize

Colorize::COLORMAP

Instance Method Summary collapse

Methods inherited from IParty::CLI::Formatter

#colorize?, descendants, find_by_id, #initialize

Methods included from Colorize

#colorize, #decolorize, #with_color

Constructor Details

This class inherits a constructor from IParty::CLI::Formatter

Instance Method Details

#format(ip, **kw, &to_data) ⇒ Object



128
129
130
# File 'lib/iparty/cli/formatter.rb', line 128

def format ip, **kw, &to_data
  JSON.pretty_generate to_data.call(ip)
end

#format_all(ips, **kw, &to_data) ⇒ Object



123
124
125
126
# File 'lib/iparty/cli/formatter.rb', line 123

def format_all ips, **kw, &to_data
  data = ips.to_h {|ip| [ip, to_data.call(ip)] }
  [JSON.pretty_generate(data)]
end

#setupObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/iparty/cli/formatter.rb', line 112

def setup
  @opts[:colorize] = false

  require "json"
rescue LoadError
  warn c("The iparty JSON output formatter requires the json gem to be installed.", :red)
  warn c("Resolution:", :yellow)
  warn c("  gem install json", :blue)
  exit 1
end