Class: Ast::Merge::SourceRender::Plan

Inherits:
Object
  • Object
show all
Defined in:
lib/ast/merge/source_render/plan.rb,
sig/ast/merge.rbs

Overview

Passive ordered render plan produced by a family provider.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources:, fragments:, metadata: {}) ⇒ Plan

Returns a new instance of Plan.

Parameters:

  • sources: (Hash[Symbol | String, String])
  • fragments: (Array[fragment])
  • metadata: (Hash[untyped, untyped]) (defaults to: {})


10
11
12
13
14
15
16
# File 'lib/ast/merge/source_render/plan.rb', line 10

def initialize(sources:, fragments:, metadata: {})
  @sources = normalize_sources(sources)
  @fragments = Array(fragments).freeze
  @metadata = .to_h.freeze

  validate!
end

Instance Attribute Details

#fragmentsArray[fragment] (readonly)

Returns the value of attribute fragments.

Returns:

  • (Array[fragment])


8
9
10
# File 'lib/ast/merge/source_render/plan.rb', line 8

def fragments
  @fragments
end

#metadataHash[untyped, untyped] (readonly)

Returns the value of attribute metadata.

Returns:

  • (Hash[untyped, untyped])


8
9
10
# File 'lib/ast/merge/source_render/plan.rb', line 8

def 
  @metadata
end

#sourcesHash[Symbol, String] (readonly)

Returns the value of attribute sources.

Returns:

  • (Hash[Symbol, String])


8
9
10
# File 'lib/ast/merge/source_render/plan.rb', line 8

def sources
  @sources
end

Instance Method Details

#source_content(fragment) ⇒ String

Parameters:

Returns:

  • (String)


22
23
24
# File 'lib/ast/merge/source_render/plan.rb', line 22

def source_content(fragment)
  source_lines(fragment.revision)[(fragment.start_line - 1)..(fragment.end_line - 1)].join
end

#source_lines(revision) ⇒ Array[String]

Parameters:

  • revision (Symbol, String)

Returns:

  • (Array[String])


18
19
20
# File 'lib/ast/merge/source_render/plan.rb', line 18

def source_lines(revision)
  sources.fetch(revision.to_sym).lines
end