Class: Yaml::Merge::FileAnalysis

Inherits:
Object
  • Object
show all
Includes:
Ast::Merge::FileAnalyzable
Defined in:
lib/yaml/merge/file_analysis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, signature_generator: nil, parser_path: nil, **_options) ⇒ FileAnalysis

Returns a new instance of FileAnalysis.



10
11
12
13
14
15
16
17
18
19
# File 'lib/yaml/merge/file_analysis.rb', line 10

def initialize(source, signature_generator: nil, parser_path: nil, **_options)
  @source = source
  @lines = source.lines.map(&:chomp)
  @signature_generator = signature_generator
  @parser_path = parser_path
  @errors = []

  DebugLogger.time('FileAnalysis#parse_yaml') { parse_yaml }
  @statements = valid? ? documents : []
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



8
9
10
# File 'lib/yaml/merge/file_analysis.rb', line 8

def ast
  @ast
end

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/yaml/merge/file_analysis.rb', line 8

def errors
  @errors
end

Instance Method Details

#documentsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/yaml/merge/file_analysis.rb', line 31

def documents
  return [] unless valid?

  index = 0
  @ast.root_node.children.filter_map do |child|
    next unless child.type.to_s == 'document'

    wrapper = NodeWrapper.new(child, lines: @lines, source: @source, document_index: index)
    index += 1
    wrapper
  end
end

#fallthrough_node?(value) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/yaml/merge/file_analysis.rb', line 46

def fallthrough_node?(value)
  value.is_a?(NodeWrapper) || super
end

#root_nodeObject



25
26
27
28
29
# File 'lib/yaml/merge/file_analysis.rb', line 25

def root_node
  return unless valid?

  NodeWrapper.new(@ast.root_node, lines: @lines, source: @source)
end

#ruleset_owner_selectorObject



50
51
52
# File 'lib/yaml/merge/file_analysis.rb', line 50

def ruleset_owner_selector
  :line_bound_statements
end

#ruleset_render_familyObject



54
55
56
# File 'lib/yaml/merge/file_analysis.rb', line 54

def ruleset_render_family
  :yaml_documents_and_mappings
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/yaml/merge/file_analysis.rb', line 21

def valid?
  @errors.empty? && !@ast.nil?
end