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.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 180

def initialize(object, file)
  super(object, file)

  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 = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr.left_expr).extract_text + '['
    @alias_of << type_expr.keys.map { |key| ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(key).extract_text }.join(', ')
    @alias_of << ']'
  else
    adapter = ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(type_expr)
    @alias_of = adapter.extract_text
  end
  @name = object.name
end

Instance Attribute Details

#alias_ofObject (readonly)

Returns the value of attribute alias_of.



175
176
177
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 175

def alias_of
  @alias_of
end

#nameObject (readonly)

Returns the value of attribute name.



174
175
176
# File 'lib/puppet-strings/yard/parsers/puppet/statement.rb', line 174

def name
  @name
end