Class: PuppetStrings::Yard::Parsers::Puppet::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-strings/yard/parsers/puppet/statement.rb

Overview

Represents the base Puppet language statement.

Constant Summary collapse

COMMENT_REGEX =

The pattern for parsing docstring comments.

/^\s*#+\s?/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, file) ⇒ Statement

Initializes the Puppet language statement.

Parameters:

  • object

    The Puppet parser model object for the statement.

  • file (String)

    The file name of the file containing the statement.



21
22
23
24
25
26
27
28
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 21

def initialize(object, file)
  @file = file

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

Instance Attribute Details

#comments_rangeObject (readonly)

Returns the value of attribute comments_range.



16
17
18
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 16

def comments_range
  @comments_range
end

#docstringObject (readonly)

Returns the value of attribute docstring.



15
16
17
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 15

def docstring
  @docstring
end

#fileObject (readonly)

Returns the value of attribute file.



13
14
15
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 13

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



14
15
16
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 14

def line
  @line
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 12

def source
  @source
end

Instance Method Details

#commentsString

Gets the full comments of the statement.

Returns:

  • (String)

    Returns the full comments of the statement.



58
59
60
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 58

def comments
  @docstring.all
end

#comments_hash_flagBoolean

Determines if the comments have hash flag.

Returns:

  • (Boolean)

    Returns true if the comments have a hash flag or false if not.



64
65
66
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 64

def comments_hash_flag
  false
end

#extract_docstring(lines) ⇒ void

This method returns an undefined value.

Extracts the docstring for the statement given the source lines.

Parameters:

  • lines (Array<String>)

    The source lines for the file containing the statement.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 33

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

#showString

Shows the first line context for the statement.

Returns:

  • (String)

    Returns the first line context for the statement.



52
53
54
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 52

def show
  "\t#{@line}: #{first_line}"
end