Sha256: 521adf609953bfb4e8f28b64afb606a8de7f8f57b94f03bbf7ffed4d2cc069ac

Contents?: true

Size: 796 Bytes

Versions: 2

Compression:

Stored size: 796 Bytes

Contents

require 'puppet-strings/yard/parsers/json/task_statement'

class PuppetStrings::Yard::Parsers::JSON::Parser < YARD::Parser::Base
  attr_reader :file, :source

  # Initializes the parser.
  # @param [String] source The source being parsed.
  # @param [String] filename The file name of the file being parsed.
  # @return [void]
  def initialize(source, filename)
    @file = filename
    @source = source
    @statements = []
  end

  def enumerator
    @statements
  end

  # Parses the source
  # @return [void]
  def parse
    begin
      json = JSON.parse(source)
      @statements.push(PuppetStrings::Yard::Parsers::JSON::TaskStatement.new(json, @source, @file))
    rescue
      log.error "Failed to parse #{@file}: "
      @statements = []
    end
    @statements.freeze
    self
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puppet-strings-2.1.0 lib/puppet-strings/yard/parsers/json/parser.rb
puppet-strings-2.0.0 lib/puppet-strings/yard/parsers/json/parser.rb