class HammerCLI::Output::Output
Attributes
context[RW]
default_adapter[RW]
Public Class Methods
adapters()
click to toggle source
# File lib/hammer_cli/output/output.rb, line 47 def self.adapters @adapters_hash ||= {} @adapters_hash end
formatters()
click to toggle source
# File lib/hammer_cli/output/output.rb, line 52 def self.formatters @formatters_hash ||= {} @formatters_hash end
new(context={}, options={})
click to toggle source
# File lib/hammer_cli/output/output.rb, line 10 def initialize(context={}, options={}) self.context = context self.default_adapter = options[:default_adapter] end
register_adapter(name, adapter_class)
click to toggle source
# File lib/hammer_cli/output/output.rb, line 57 def self.register_adapter(name, adapter_class) adapters[name] = adapter_class end
register_formatter(formatter, *field_types)
click to toggle source
# File lib/hammer_cli/output/output.rb, line 61 def self.register_formatter(formatter, *field_types) field_types.each do |type| formatter_list = formatters[type] || [] formatter_list << formatter formatters[type] = formatter_list end end
Public Instance Methods
adapter()
click to toggle source
# File lib/hammer_cli/output/output.rb, line 36 def adapter adapter_name = context[:adapter] || default_adapter begin init_adapter(adapter_name.to_sym) rescue NameError Logging.logger[self.class.name].warn("Required adapter '#{adapter_name}' was not found, using 'base' instead") init_adapter(:base) end end
print_collection(definition, collection)
click to toggle source
# File lib/hammer_cli/output/output.rb, line 29 def print_collection(definition, collection) unless collection.class <= HammerCLI::Output::RecordCollection collection = HammerCLI::Output::RecordCollection.new([collection].flatten(1)) end adapter.print_collection(definition.fields, collection) end
print_error(msg, details=nil, msg_params={})
click to toggle source
# File lib/hammer_cli/output/output.rb, line 21 def print_error(msg, details=nil, msg_params={}) adapter.print_error(msg.to_s, details, msg_params) end
print_message(msg, msg_params={})
click to toggle source
# File lib/hammer_cli/output/output.rb, line 17 def print_message(msg, msg_params={}) adapter.print_message(msg.to_s, msg_params) end
print_record(definition, record)
click to toggle source
# File lib/hammer_cli/output/output.rb, line 25 def print_record(definition, record) adapter.print_record(definition.fields, record) end
Private Instance Methods
init_adapter(adapter_name)
click to toggle source
# File lib/hammer_cli/output/output.rb, line 73 def init_adapter(adapter_name) raise NameError unless self.class.adapters.has_key? adapter_name @adapter ||= self.class.adapters[adapter_name].new(context, self.class.formatters) end