Class: HammerCLI::Output::Output
- Inherits:
-
Object
- Object
- HammerCLI::Output::Output
- Defined in:
- lib/hammer_cli/output/output.rb
Instance Attribute Summary collapse
-
#default_adapter ⇒ Object
Returns the value of attribute default_adapter.
Class Method Summary collapse
- .adapters ⇒ Object
- .formatters ⇒ Object
- .register_adapter(name, adapter_class) ⇒ Object
- .register_formatter(formatter, *field_types) ⇒ Object
Instance Method Summary collapse
- #adapter ⇒ Object
-
#initialize(context = {}, options = {}) ⇒ Output
constructor
A new instance of Output.
- #print_collection(definition, collection, options = {}) ⇒ Object
- #print_error(msg, details = nil, msg_params = {}, options = {}) ⇒ Object
- #print_message(msg, msg_params = {}, options = {}) ⇒ Object
- #print_record(definition, record) ⇒ Object
Constructor Details
Instance Attribute Details
#default_adapter ⇒ Object
Returns the value of attribute default_adapter.
16 17 18 |
# File 'lib/hammer_cli/output/output.rb', line 16 def default_adapter @default_adapter end |
Class Method Details
.adapters ⇒ Object
48 49 50 51 |
# File 'lib/hammer_cli/output/output.rb', line 48 def self.adapters @adapters_hash ||= {} @adapters_hash end |
.formatters ⇒ Object
53 54 55 56 |
# File 'lib/hammer_cli/output/output.rb', line 53 def self.formatters @formatters_hash ||= {} @formatters_hash end |
.register_adapter(name, adapter_class) ⇒ Object
58 59 60 |
# File 'lib/hammer_cli/output/output.rb', line 58 def self.register_adapter(name, adapter_class) adapters[name] = adapter_class end |
.register_formatter(formatter, *field_types) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/hammer_cli/output/output.rb', line 62 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 |
Instance Method Details
#adapter ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hammer_cli/output/output.rb', line 37 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, options = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hammer_cli/output/output.rb', line 30 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, ) if appropriate_verbosity?(:collection) end |
#print_error(msg, details = nil, msg_params = {}, options = {}) ⇒ Object
22 23 24 |
# File 'lib/hammer_cli/output/output.rb', line 22 def print_error(msg, details=nil, msg_params = {}, = {}) adapter.print_error(msg.to_s, details, msg_params) if appropriate_verbosity?(:error, ) end |
#print_message(msg, msg_params = {}, options = {}) ⇒ Object
18 19 20 |
# File 'lib/hammer_cli/output/output.rb', line 18 def (msg, msg_params = {}, = {}) adapter.(msg.to_s, msg_params) if appropriate_verbosity?(:message, ) end |
#print_record(definition, record) ⇒ Object
26 27 28 |
# File 'lib/hammer_cli/output/output.rb', line 26 def print_record(definition, record) adapter.print_record(definition.fields, record) if appropriate_verbosity?(:record) end |