Module: Berkshelf::Formatters
- Defined in:
- lib/berkshelf/formatters.rb,
lib/berkshelf/formatters/json.rb,
lib/berkshelf/formatters/null.rb,
lib/berkshelf/formatters/human_readable.rb
Defined Under Namespace
Modules: AbstractFormatter Classes: HumanReadable, JSON, Null
Constant Summary collapse
- @@formatters =
Hash.new
Class Method Summary collapse
-
.formatters ⇒ Hash
Access the formatters map that links string symbols to Formatter implementations.
- .get(id) ⇒ ~AbstractFormatter? (also: [])
-
.register(id, klass) ⇒ Hash
A hash of registered formatters.
Class Method Details
.formatters ⇒ Hash
Access the formatters map that links string symbols to Formatter implementations
10 11 12 |
# File 'lib/berkshelf/formatters.rb', line 10 def formatters @@formatters end |
.get(id) ⇒ ~AbstractFormatter? Also known as: []
38 39 40 41 42 43 44 |
# File 'lib/berkshelf/formatters.rb', line 38 def get(id) unless id.respond_to?(:to_sym) raise ArgumentError, "Invalid Formatter ID: must respond to #to_sym. You gave: #{id}" end self.formatters.fetch(id.to_sym, nil) end |
.register(id, klass) ⇒ Hash
Returns a hash of registered formatters.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/berkshelf/formatters.rb', line 22 def register(id, klass) unless id.respond_to?(:to_sym) raise ArgumentError, "Invalid Formatter ID: must respond to #to_sym. You gave: #{id}" end id = id.to_sym if self.formatters.has_key?(id) raise Berkshelf::InternalError, "Formatter ID '#{id}' already registered" end self.formatters[id] = klass end |