Class: Igniter::Contracts::Assembly::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/contracts/assembly/profile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes:, dsl_keywords:, validators:, normalizers:, runtime_handlers:, diagnostics_contributors:, pack_manifests:, effects:, executors:, fingerprint:) ⇒ Profile

Returns a new instance of Profile.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/igniter/contracts/assembly/profile.rb', line 62

def initialize(nodes:, dsl_keywords:, validators:, normalizers:, runtime_handlers:, diagnostics_contributors:,
               pack_manifests:, effects:, executors:, fingerprint:)
  @nodes = nodes
  @dsl_keywords = dsl_keywords
  @validators = validators
  @normalizers = normalizers
  @runtime_handlers = runtime_handlers
  @diagnostics_contributors = diagnostics_contributors
  @pack_manifests = pack_manifests
  @effects = effects
  @executors = executors
  @fingerprint = fingerprint
  freeze
end

Instance Attribute Details

#diagnostics_contributorsObject (readonly)

Returns the value of attribute diagnostics_contributors.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def diagnostics_contributors
  @diagnostics_contributors
end

#dsl_keywordsObject (readonly)

Returns the value of attribute dsl_keywords.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def dsl_keywords
  @dsl_keywords
end

#effectsObject (readonly)

Returns the value of attribute effects.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def effects
  @effects
end

#executorsObject (readonly)

Returns the value of attribute executors.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def executors
  @executors
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def fingerprint
  @fingerprint
end

#nodesObject (readonly)

Returns the value of attribute nodes.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def nodes
  @nodes
end

#normalizersObject (readonly)

Returns the value of attribute normalizers.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def normalizers
  @normalizers
end

#pack_manifestsObject (readonly)

Returns the value of attribute pack_manifests.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def pack_manifests
  @pack_manifests
end

#runtime_handlersObject (readonly)

Returns the value of attribute runtime_handlers.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def runtime_handlers
  @runtime_handlers
end

#validatorsObject (readonly)

Returns the value of attribute validators.



9
10
11
# File 'lib/igniter/contracts/assembly/profile.rb', line 9

def validators
  @validators
end

Class Method Details

.build_from(kernel) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/igniter/contracts/assembly/profile.rb', line 20

def self.build_from(kernel)
  payload = {
    nodes: kernel.nodes.to_h.freeze,
    dsl_keywords: kernel.dsl_keywords.to_h.freeze,
    validators: kernel.validators.entries.freeze,
    normalizers: kernel.normalizers.entries.freeze,
    runtime_handlers: kernel.runtime_handlers.to_h.freeze,
    diagnostics_contributors: kernel.diagnostics_contributors.entries.freeze,
    pack_manifests: kernel.pack_manifests.dup.freeze,
    effects: kernel.effects.to_h.freeze,
    executors: kernel.executors.to_h.freeze
  }

  new(**payload, fingerprint: fingerprint_for(payload))
end

.fingerprint_for(payload) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/igniter/contracts/assembly/profile.rb', line 36

def self.fingerprint_for(payload)
  normalized = payload.map do |key, value|
    serialized = serialize_for_fingerprint(value)
    [key.to_s, serialized]
  end

  Digest::SHA256.hexdigest(normalized.inspect)
end

.serialize_for_fingerprint(value) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/igniter/contracts/assembly/profile.rb', line 45

def self.serialize_for_fingerprint(value)
  case value
  when Hash
    value.map { |entry_key, entry_value| [entry_key.to_s, entry_value.inspect] }
  when Array
    value.map do |entry|
      if entry.respond_to?(:key) && entry.respond_to?(:value)
        [entry.key.to_s, entry.value.inspect]
      else
        entry.inspect
      end
    end
  else
    value.inspect
  end
end

Instance Method Details

#declared_registry_keys(registry) ⇒ Object



125
126
127
128
129
# File 'lib/igniter/contracts/assembly/profile.rb', line 125

def declared_registry_keys(registry)
  pack_manifests
    .flat_map { |manifest| manifest.declared_keys_for(registry) }
    .uniq
end

#dsl_keyword(name) ⇒ Object



81
82
83
# File 'lib/igniter/contracts/assembly/profile.rb', line 81

def dsl_keyword(name)
  dsl_keywords.fetch(name.to_sym)
end

#effect(name) ⇒ Object



89
90
91
# File 'lib/igniter/contracts/assembly/profile.rb', line 89

def effect(name)
  effects.fetch(name.to_sym)
end

#executor(name) ⇒ Object



93
94
95
# File 'lib/igniter/contracts/assembly/profile.rb', line 93

def executor(name)
  executors.fetch(name.to_sym)
end

#node_class(kind) ⇒ Object



77
78
79
# File 'lib/igniter/contracts/assembly/profile.rb', line 77

def node_class(kind)
  nodes.fetch(kind.to_sym)
end

#pack_manifest(name) ⇒ Object



113
114
115
# File 'lib/igniter/contracts/assembly/profile.rb', line 113

def pack_manifest(name)
  pack_manifests.find { |manifest| manifest.name == name.to_sym }
end

#pack_namesObject



109
110
111
# File 'lib/igniter/contracts/assembly/profile.rb', line 109

def pack_names
  pack_manifests.map(&:name)
end

#provided_capabilitiesObject



117
118
119
# File 'lib/igniter/contracts/assembly/profile.rb', line 117

def provided_capabilities
  pack_manifests.flat_map(&:provides_capabilities).uniq
end

#required_capabilitiesObject



121
122
123
# File 'lib/igniter/contracts/assembly/profile.rb', line 121

def required_capabilities
  pack_manifests.flat_map(&:requires_capabilities).uniq
end

#runtime_handler(kind) ⇒ Object



85
86
87
# File 'lib/igniter/contracts/assembly/profile.rb', line 85

def runtime_handler(kind)
  runtime_handlers.fetch(kind.to_sym)
end

#supports_effect?(name) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/igniter/contracts/assembly/profile.rb', line 101

def supports_effect?(name)
  effects.key?(name.to_sym)
end

#supports_executor?(name) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/igniter/contracts/assembly/profile.rb', line 105

def supports_executor?(name)
  executors.key?(name.to_sym)
end

#supports_node_kind?(kind) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/igniter/contracts/assembly/profile.rb', line 97

def supports_node_kind?(kind)
  nodes.key?(kind.to_sym)
end