Class: PuppetStrings::Yard::Parsers::Puppet::DataTypeAliasStatement

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

Overview

Implements the Puppet data type alias statement.

Constant Summary

Constants inherited from Statement

Statement::COMMENT_REGEX

Instance Attribute Summary collapse

Attributes inherited from Statement

#comments_range, #docstring, #file, #line, #source

Instance Method Summary collapse

Methods inherited from Statement

#comments, #comments_hash_flag, #extract_docstring, #show

Constructor Details

#initialize(object, file) ⇒ DataTypeAliasStatement

Initializes the Puppet data type alias statement.

Parameters:

  • object (Puppet::Pops::Model::TypeAlias)

    The model object for the type statement.

  • file (String)

    The file containing the statement.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 166

def initialize(object, file)
  super

  type_expr = object.type_expr
  case type_expr
  when Puppet::Pops::Model::AccessExpression
    # TODO: I don't like rebuilding the source from the AST, but AccessExpressions don't expose the original source
    @alias_of = +"#{PuppetStrings::Yard::Util.ast_to_text(type_expr.left_expr)}[" # alias_of should be mutable so we add a + to the string.
    @alias_of << type_expr.keys.map { |key| PuppetStrings::Yard::Util.ast_to_text(key) }.join(', ')
    @alias_of << ']'
  else
    @alias_of = PuppetStrings::Yard::Util.ast_to_text(type_expr)
  end
  @name = object.name
end

Instance Attribute Details

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



161
162
163
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 161

def alias_of
  @alias_of
end

#nameObject (readonly)

Returns the value of attribute name.



161
162
163
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 161

def name
  @name
end