Class: PuppetX::PuppetLabs::Strings::Pops::YARDStatement

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb

Overview

An adapter class that conforms a Pops model instance + adapters to the interface expected by YARD handlers.

FIXME: Inhertiting from OpenStruct is a bit of a hack. It allows attributes to be declared as needed but in the long run understandibility of the code would be improved by having a concrete model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pops_obj) ⇒ YARDStatement

Returns a new instance of YARDStatement.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 12

def initialize(pops_obj)
  # Initialize OpenStruct
  super({})

  unless pops_obj.is_a? Puppet::Pops::Model::PopsObject
    raise ArgumentError, "A YARDStatement can only be initialized from a PopsObject. Got a: #{pops_obj.class}"
  end

  @pops_obj = pops_obj
  @pos_adapter = Puppet::Pops::Adapters::SourcePosAdapter.adapt(@pops_obj)
  # FIXME: Perhaps this should be a seperate adapter?
  @comments = extract_comments
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



10
11
12
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 10

def comments
  @comments
end

#pops_objObject (readonly)

Returns the value of attribute pops_obj.



10
11
12
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 10

def pops_obj
  @pops_obj
end

Instance Method Details

#comments_hash_flagObject



42
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 42

def comments_hash_flag; nil end

#comments_rangeObject



43
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 43

def comments_range; nil end

#lineObject



30
31
32
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 30

def line
  @line ||= @pos_adapter.line
end

#sourceObject Also known as: show



34
35
36
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 34

def source
  @source ||= @pos_adapter.extract_text
end

#typeObject



26
27
28
# File 'lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb', line 26

def type
  pops_obj.class
end