Class: TTY::Config::MarshallerRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/config/marshaller_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappings = {}) ⇒ MarshallerRegistry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MarshallerRegistry.



12
13
14
# File 'lib/tty/config/marshaller_registry.rb', line 12

def initialize(mappings = {})
  @marshallers = mappings
end

Instance Attribute Details

#marshallersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

All registered marshallers



9
10
11
# File 'lib/tty/config/marshaller_registry.rb', line 9

def marshallers
  @marshallers
end

Instance Method Details

#[](name) ⇒ Object



40
41
42
# File 'lib/tty/config/marshaller_registry.rb', line 40

def [](name)
  marshallers.fetch(name)
end

#extsObject



24
25
26
# File 'lib/tty/config/marshaller_registry.rb', line 24

def exts
  marshallers.values.reduce([]) { |acc, obj| acc + obj.ext }
end

#namesObject



16
17
18
# File 'lib/tty/config/marshaller_registry.rb', line 16

def names
  marshallers.keys
end

#objectsObject



20
21
22
# File 'lib/tty/config/marshaller_registry.rb', line 20

def objects
  marshallers.values
end

#register(name, object) ⇒ Object



32
33
34
# File 'lib/tty/config/marshaller_registry.rb', line 32

def register(name, object)
  marshallers[name] = object
end

#registered?(name_or_object) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/tty/config/marshaller_registry.rb', line 28

def registered?(name_or_object)
  marshallers.key?(name_or_object) || marshallers.value?(name_or_object)
end

#unregister(name) ⇒ Object



36
37
38
# File 'lib/tty/config/marshaller_registry.rb', line 36

def unregister(name)
  marshallers.delete(name)
end