class PuppetStrings::Yard::Parsers::Puppet::Statement

Represents the base Puppet language statement.

Constants

COMMENT_REGEX

The pattern for parsing docstring comments.

Attributes

comments_range[R]
docstring[R]
file[R]
line[R]
source[R]

Public Class Methods

new(object, file) click to toggle source

Initializes the Puppet language statement. @param object The Puppet parser model object for the statement. @param [String] file The file name of the file containing the statement.

# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 19
def initialize(object, file)
  @file = file

  adapter = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(object)
  @source = adapter.extract_text
  @line = adapter.line
  @comments_range = nil
end

Public Instance Methods

comments() click to toggle source

Gets the full comments of the statement. @return [String] Returns the full comments of the statement.

# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 54
def comments
  @docstring.all
end
comments_hash_flag() click to toggle source

Determines if the comments have hash flag. @return [Boolean] Returns true if the comments have a hash flag or false if not.

# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 60
def comments_hash_flag
  false
end
extract_docstring(lines) click to toggle source

Extracts the docstring for the statement given the source lines. @param [Array<String>] lines The source lines for the file containing the statement. @return [void]

# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 31
def extract_docstring(lines)
  comment = []
  (0..@line-2).reverse_each do |index|
    break unless index <= lines.count
    line = lines[index].strip
    count = line.size
    line.gsub!(COMMENT_REGEX, '')
    # Break out if nothing was removed (wasn't a comment line)
    break unless line.size < count
    comment << line
  end
  @comments_range = (@line - comment.size - 1..@line - 1)
  @docstring = YARD::Docstring.new(comment.reverse.join("\n"))
end
show() click to toggle source

Shows the first line context for the statement. @return [String] Returns the first line context for the statement.

# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 48
def show
  "\t#{@line}: #{first_line}"
end

Private Instance Methods

first_line() click to toggle source
# File lib/puppet-strings/yard/parsers/puppet/statement.rb, line 65
def first_line
  @source.split(/\r?\n/).first.strip
end