Class: AgentClientProtocol::TypeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_client_protocol/type_registry.rb

Class Method Summary collapse

Class Method Details

.all(unstable: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/agent_client_protocol/type_registry.rb', line 22

def all(unstable: false)
  ensure_loaded!(unstable: unstable)
  namespace = unstable ? Types::Unstable : Types

  namespace.constants(false).sort.each_with_object({}) do |const_name, acc|
    klass = namespace.const_get(const_name, false)
    next unless klass.is_a?(Class)
    next unless klass.respond_to?(:definition_name)
    next if klass.definition_name.nil?

    acc[const_name.to_s] = klass
  end
end

.build(definition_name, payload, unstable: false) ⇒ Object



36
37
38
39
40
41
# File 'lib/agent_client_protocol/type_registry.rb', line 36

def build(definition_name, payload, unstable: false)
  klass = fetch(definition_name, unstable: unstable)
  return payload if klass.nil?

  klass.coerce(payload)
end

.fetch(definition_name, unstable: false) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/agent_client_protocol/type_registry.rb', line 14

def fetch(definition_name, unstable: false)
  ensure_loaded!(unstable: unstable)
  namespace = unstable ? Types::Unstable : Types
  return nil unless namespace.const_defined?(definition_name, false)

  namespace.const_get(definition_name, false)
end