Class: Payload::DefinitionList Private

Inherits:
Object
  • Object
show all
Defined in:
lib/payload/definition_list.rb

Overview

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

Immutable list of definitions.

Used internally by Container to define and look up definitions.

Instance Method Summary collapse

Constructor Details

#initialize(definitions = {}) ⇒ DefinitionList

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 DefinitionList.



12
13
14
# File 'lib/payload/definition_list.rb', line 12

def initialize(definitions = {})
  @definitions = definitions
end

Instance Method Details

#add(name, resolver) ⇒ Object

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.



16
17
18
19
# File 'lib/payload/definition_list.rb', line 16

def add(name, resolver)
  value = find(name).set(Definition.new(name, resolver))
  self.class.new(definitions.merge(name => value))
end

#decorate(name, block) ⇒ Object

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.



25
26
27
28
# File 'lib/payload/definition_list.rb', line 25

def decorate(name, block)
  decorated = find(name).decorate(block)
  self.class.new(@definitions.merge(name => decorated))
end

#export(names) ⇒ Object

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.



30
31
32
33
34
35
36
# File 'lib/payload/definition_list.rb', line 30

def export(names)
  exported_definitions = names.inject({}) do |result, name|
    result.merge! name => ExportedDefinition.new(find(name), self)
  end

  self.class.new exported_definitions
end

#find(name) ⇒ Object

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.



21
22
23
# File 'lib/payload/definition_list.rb', line 21

def find(name)
  definitions.fetch(name) { UndefinedDefinition.new(name) }
end

#import(imports) ⇒ Object

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.



38
39
40
# File 'lib/payload/definition_list.rb', line 38

def import(imports)
  self.class.new definitions.merge(imports.definitions)
end