Class: PuppetStrings::Yard::CodeObjects::Provider

Inherits:
Base
  • Object
show all
Defined in:
lib/puppet-strings/yard/code_objects/provider.rb

Overview

Implements the Puppet provider code object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

new

Constructor Details

#initialize(type_name, name) ⇒ void

Initializes a Puppet provider code object.

Parameters:

  • type_name (String)

    The resource type name for the provider.

  • name (String)

    The name of the provider.s



28
29
30
31
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 28

def initialize(type_name, name)
  @type_name = type_name
  super(PuppetStrings::Yard::CodeObjects::Providers.instance(type_name), name)
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 22

def commands
  @commands
end

#confinesObject (readonly)

Returns the value of attribute confines.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 22

def confines
  @confines
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 22

def defaults
  @defaults
end

#featuresObject (readonly)

Returns the value of attribute features.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 22

def features
  @features
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



22
23
24
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 22

def type_name
  @type_name
end

Instance Method Details

#add_command(key, value) ⇒ void

This method returns an undefined value.

Adds a command to the provider.

Parameters:

  • key (String)

    The command’s key.

  • value (String)

    The command’s value.



71
72
73
74
75
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 71

def add_command(key, value)
  return unless key && value
  @commands ||= {}
  @commands[key] = value
end

#add_confine(key, value) ⇒ void

This method returns an undefined value.

Adds a confine to the provider.

Parameters:

  • key (String)

    The confine’s key.

  • value (String)

    The confine’s value.



43
44
45
46
47
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 43

def add_confine(key, value)
  return unless key && value
  @confines ||= {}
  @confines[key] = value
end

#add_default(constraints) ⇒ void

This method returns an undefined value.

Adds a default to the provider.

Parameters:

  • constraints (Array)

    List of related key-pair values for the default.



61
62
63
64
65
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 61

def add_default(constraints)
  return unless constraints
  @defaults ||= []
  @defaults << constraints
end

#add_feature(feature) ⇒ void

This method returns an undefined value.

Adds a feature to the provider.

Parameters:

  • feature (String)

    The feature to add to the provider.



52
53
54
55
56
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 52

def add_feature(feature)
  return unless feature
  @features ||= []
  @features << feature
end

#to_hashHash

Converts the code object to a hash representation.

Returns:

  • (Hash)

    Returns a hash representation of the code object.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 79

def to_hash
  hash = {}
  hash[:name] = name
  hash[:type_name] = type_name
  hash[:file] = file
  hash[:line] = line
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
  hash[:confines] = confines if confines && !confines.empty?
  hash[:features] = features if features && !features.empty?
  hash[:defaults] = defaults if defaults && !defaults.empty?
  hash[:commands] = commands if commands && !commands.empty?
  hash
end

#typeObject

Gets the type of the code object.

Returns:

  • Returns the type of the code object.



35
36
37
# File 'lib/puppet-strings/yard/code_objects/provider.rb', line 35

def type
  :puppet_provider
end