Sha256: cd05c0a2e141d5a84265fa169595b68a2e9d2fa1048af8287eea544ee5e8ee65

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

require 'puppet-strings/yard/code_objects/group'

# Implements the group for Puppet tasks.
class PuppetStrings::Yard::CodeObjects::Tasks < PuppetStrings::Yard::CodeObjects::Group
  # Gets the singleton instance of the group.
  # @return Returns the singleton instance of the group.
  def self.instance
    super(:puppet_tasks)
  end

  # Gets the display name of the group.
  # @param [Boolean] prefix whether to show a prefix. Ignored for Puppet group namespaces.
  # @return [String] Returns the display name of the group.
  def name(_prefix = false)
    'Puppet Tasks'
  end
end

# Implements the Puppet task code object.
class PuppetStrings::Yard::CodeObjects::Task < PuppetStrings::Yard::CodeObjects::Base
  attr_reader :statement

  # Initializes a JSON task code object.
  # @param statement TaskStatement object
  # @return [void]
  def initialize(statement)
    @name = statement.name
    @statement = statement
    super(PuppetStrings::Yard::CodeObjects::Tasks.instance, name)
  end

  # Gets the type of the code object.
  # @return Returns the type of the code object.
  def type
    :puppet_task
  end

  # Gets the source of the code object.
  # @return Returns the source of the code object.
  def source
    @statement.source
  end

  def parameters
    statement.parameters.map do |name, props|
      { name: name.to_s,
        tag_name: 'param',
        text: props['description'] || '',
        types: [props['type']] || '' }
    end
  end

  # Converts the code object to a hash representation.
  # @return [Hash] Returns a hash representation of the code object.
  def to_hash
    { name: name.to_s,
      file: statement.file,
      line: statement.line,
      docstring: {
        text: statement.docstring,
        tags: parameters
      },
      source: statement.source,
      supports_noop: statement.json['supports_noop'] || false,
      input_method: statement.json['input_method'] }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-strings-4.1.3 lib/puppet-strings/yard/code_objects/task.rb