Module: Legion::Extensions::MindGrowth::Runners::Builder

Extended by:
Builder
Includes:
Helpers::Lex
Included in:
Builder
Defined in:
lib/legion/extensions/mind_growth/runners/builder.rb

Instance Method Summary collapse

Instance Method Details

#build_extension(proposal_id:, base_path: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/legion/extensions/mind_growth/runners/builder.rb', line 13

def build_extension(proposal_id:, base_path: nil, **)
  proposal = find_proposal(proposal_id)
  return { success: false, error: :not_found } unless proposal

  pipeline = Helpers::BuildPipeline.new(proposal)
  proposal.transition!(:building)
  persist_proposal(proposal)
  base_path ||= ::Dir.pwd

  run_stage(pipeline, :scaffold,  -> { scaffold_stage(proposal, base_path) })
  run_stage(pipeline, :implement, -> { implement_stage(proposal, base_path) }) unless pipeline.failed?
  run_stage(pipeline, :test,      -> { test_stage(proposal, base_path) }) unless pipeline.failed?
  run_stage(pipeline, :validate,  -> { validate_stage(proposal, base_path) }) unless pipeline.failed?
  run_stage(pipeline, :register,  -> { register_stage(proposal) }) unless pipeline.failed?

  proposal.transition!(pipeline.complete? ? :passing : :build_failed)
  persist_proposal(proposal)
  log.info "[mind_growth:builder] #{proposal.name}: #{pipeline.stage}"
  { success: pipeline.complete?, pipeline: pipeline.to_h, proposal: proposal.to_h }
rescue ArgumentError => e
  { success: false, error: e.message }
end

#build_status(proposal_id:) ⇒ Object



36
37
38
39
40
41
# File 'lib/legion/extensions/mind_growth/runners/builder.rb', line 36

def build_status(proposal_id:, **)
  proposal = find_proposal(proposal_id)
  return { success: false, error: :not_found } unless proposal

  { success: true, name: proposal.name, status: proposal.status }
end