Module: Ea::Cli::Output
- Defined in:
- lib/ea/cli/output.rb,
lib/ea/cli/output/formatter.rb,
lib/ea/cli/output/json_formatter.rb,
lib/ea/cli/output/yaml_formatter.rb,
lib/ea/cli/output/table_formatter.rb
Overview
Output formatters for the CLI. Each formatter self-registers via
Ea::Cli::Output.register(:name, Class) at file-load time. Lookup via
Ea::Cli::Output.for(:name) triggers autoloads on first access.
Defined Under Namespace
Classes: Formatter, JsonFormatter, TableFormatter, YamlFormatter
Class Method Summary collapse
- .for(name) ⇒ Object
-
.instance_for(name) ⇒ Object
Convenience: returns a fresh formatter instance for
name. - .register(name, klass) ⇒ Object
- .registered_formats ⇒ Object
Class Method Details
.for(name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/ea/cli/output.rb', line 22 def for(name) ensure_formatters_loaded klass = @formatters[name.to_sym] klass || raise(ArgumentError, "No output formatter '#{name}'. " \ "Registered: #{@formatters.keys.join(', ')}") end |
.instance_for(name) ⇒ Object
Convenience: returns a fresh formatter instance for name.
32 33 34 |
# File 'lib/ea/cli/output.rb', line 32 def instance_for(name) self.for(name).new end |
.register(name, klass) ⇒ Object
18 19 20 |
# File 'lib/ea/cli/output.rb', line 18 def register(name, klass) @formatters[name.to_sym] = klass end |
.registered_formats ⇒ Object
36 37 38 39 |
# File 'lib/ea/cli/output.rb', line 36 def registered_formats ensure_formatters_loaded @formatters.keys end |