Class: IgniterLang::InternalProfileAssembly

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter_lang/internal_profile_assembly.rb

Constant Summary collapse

KIND =
"internal_profile_assembly_result"
FORMAT_VERSION =
"0.1.0"
SOURCE_PACKET_KIND =
"compiler_profile_oof_registry_source_input"
IMPLEMENTATION_CANDIDATE =
"implementation_candidate"
FINALIZED_INTERNAL =
"finalized_internal"
FINALIZED_INTERNAL_MEANING =
"internal assembly state only; not PROP-036 finalization, not compiler_profile_id, " \
"and not manifest/profile identity"
CLOSED_SURFACE_ASSERTIONS =
{
  "root_require" => false,
  "compiler_pipeline_usage" => false,
  "public_api_cli" => false,
  "loader_report" => false,
  "compatibility_report" => false,
  "igapp_mutation" => false,
  "manifest_mutation" => false,
  "prop036_mutation" => false,
  "prop038_mutation" => false,
  "runtime_behavior" => false,
  "production_behavior" => false,
  "spark_surface" => false
}.freeze
DIAG_INVALID_SOURCE_PACKET =
"internal_profile_assembly.invalid_source_packet"
DIAG_INVALID_LIFECYCLE_STATE =
"internal_profile_assembly.invalid_lifecycle_state"
DIAG_PACKET_MAPPING_FAILED =
"internal_profile_assembly.packet_mapping_failed"
DIAG_PACKET_VALIDATION_FAILED =
"internal_profile_assembly.packet_validation_failed"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_packet:, registry_validator:) ⇒ InternalProfileAssembly

Returns a new instance of InternalProfileAssembly.



55
56
57
58
# File 'lib/igniter_lang/internal_profile_assembly.rb', line 55

def initialize(source_packet:, registry_validator:)
  @source_packet = source_packet
  @registry_validator = registry_validator
end

Class Method Details

.assemble(source_packet:, registry_validator: IgniterLang::OOFFragmentRegistry.new) ⇒ Object



51
52
53
# File 'lib/igniter_lang/internal_profile_assembly.rb', line 51

def self.assemble(source_packet:, registry_validator: IgniterLang::OOFFragmentRegistry.new)
  new(source_packet: source_packet, registry_validator: registry_validator).assemble
end

Instance Method Details

#assembleObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/igniter_lang/internal_profile_assembly.rb', line 60

def assemble
  diagnostics = []
  packet_hash = nil
  helper_envelopes = nil
  validation = nil
  input_lifecycle_state = lifecycle_state_of(@source_packet)

  unless source_packet_compatible?(@source_packet)
    diagnostics << diag(DIAG_INVALID_SOURCE_PACKET,
      "source_packet must support lifecycle_state, to_h, to_helper_envelopes, and validate_with")
    return build_result(false, input_lifecycle_state, diagnostics, packet_hash, helper_envelopes, validation)
  end

  if input_lifecycle_state != IMPLEMENTATION_CANDIDATE
    diagnostics << diag(DIAG_INVALID_LIFECYCLE_STATE,
      "source_packet lifecycle_state must be #{IMPLEMENTATION_CANDIDATE.inspect}, " \
      "got #{input_lifecycle_state.inspect}")
  end

  begin
    packet_hash = @source_packet.to_h
    helper_envelopes = @source_packet.to_helper_envelopes
  rescue StandardError => e
    diagnostics << diag(DIAG_PACKET_MAPPING_FAILED, "#{e.class}: #{e.message}")
    return build_result(false, input_lifecycle_state, diagnostics, packet_hash, helper_envelopes, validation)
  end

  unless packet_hash.is_a?(Hash) && packet_hash["kind"] == SOURCE_PACKET_KIND
    diagnostics << diag(DIAG_INVALID_SOURCE_PACKET,
      "source_packet.to_h must return kind #{SOURCE_PACKET_KIND.inspect}")
  end

  begin
    validation = @source_packet.validate_with(registry_validator: @registry_validator)
  rescue StandardError => e
    diagnostics << diag(DIAG_PACKET_VALIDATION_FAILED, "#{e.class}: #{e.message}")
    return build_result(false, input_lifecycle_state, diagnostics, packet_hash, helper_envelopes, validation)
  end

  diagnostics.concat(internal_diagnostics_from(validation))
  valid = diagnostics.empty? && validation.fetch("valid", false)

  build_result(valid, input_lifecycle_state, diagnostics, packet_hash, helper_envelopes, validation)
end