class PuppetStrings::Yard::Parsers::JSON::Parser

Implementas a JSON parser.

Attributes

file[R]
source[R]

Public Class Methods

new(source, filename) click to toggle source

Initializes the parser. @param [String] source The source being parsed. @param [String] filename The file name of the file being parsed. @return [void]

# File lib/puppet-strings/yard/parsers/json/parser.rb, line 13
def initialize(source, filename) # rubocop:disable Lint/MissingSuper
  @file = filename
  @source = source
  @statements = []
end

Public Instance Methods

enumerator() click to toggle source
# File lib/puppet-strings/yard/parsers/json/parser.rb, line 19
def enumerator
  @statements
end
parse() click to toggle source

Parses the source @return [void]

# File lib/puppet-strings/yard/parsers/json/parser.rb, line 25
def parse
  begin
    json = JSON.parse(source)
    # TODO: this should compare json to a Task metadata json-schema or perform some other hueristics
    # to determine what type of statement it represents
    @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file)) unless json.empty?
  rescue StandardError
    log.error "Failed to parse #{@file}: "
    @statements = []
  end
  @statements.freeze
  self
end