Class: Puppet::Generate::Type::Input Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/generate/type.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents an input to the type generator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, path, format) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes an input.

Parameters:

  • base (String)

    The base path where the input is located.

  • path (String)

    The path to the input file.

  • format (Symbol)

    The format to use for generation.



24
25
26
27
28
# File 'lib/puppet/generate/type.rb', line 24

def initialize(base, path, format)
  @base = base
  @path = path
  self.format = format
end

Instance Attribute Details

#formatObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the format to use for generating the output file.



17
18
19
# File 'lib/puppet/generate/type.rb', line 17

def format
  @format
end

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the path to the input.



14
15
16
# File 'lib/puppet/generate/type.rb', line 14

def path
  @path
end

Class Method Details

.supported_format?(format) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the given format is supported

Parameters:

  • format (Symbol)

    The format to use for generation.

Returns:

  • (Boolean)

    Returns true if the format is supported or false if not.



107
108
109
# File 'lib/puppet/generate/type.rb', line 107

def self.supported_format?(format)
  [:pcore].include?(format)
end

Instance Method Details

#effective_output_path(outputdir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the outputpath to use given an outputdir that may be nil If outputdir is not nil, the returned path is relative to that outpudir otherwise determined by this input.

Parameters:

  • The (String, nil)

    outputdirectory to use, or nil if to be determined by this Input



88
89
90
# File 'lib/puppet/generate/type.rb', line 88

def effective_output_path(outputdir)
  outputdir ? File.join(outputdir, output_name) : output_path
end

#output_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the filename of the output file.

Returns:

  • (String)

    Returns the name to the output file.



55
56
57
58
59
60
61
62
63
# File 'lib/puppet/generate/type.rb', line 55

def output_name
  @output_name ||=
    case @format
    when :pcore
      "#{File.basename(@path, '.rb')}.pp"
    else
      raise _("unsupported format '%{format}'.") % { format: @format }
    end
end

#output_pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the path to the output file.

Returns:

  • (String)

    Returns the path to the output file.



67
68
69
70
71
72
73
74
75
# File 'lib/puppet/generate/type.rb', line 67

def output_path
  @output_path ||=
    case @format
    when :pcore
      File.join(@base, 'pcore', 'types', output_name)
    else
      raise _("unsupported format '%{format}'.") % { format: @format }
    end
end

#output_path=(path) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the path to the output file.

Parameters:

  • path (String)

    The new path to the output file.

Returns:

  • (String)

    Returns the new path to the output file.



80
81
82
# File 'lib/puppet/generate/type.rb', line 80

def output_path=(path)
  @output_path = path
end

#template_pathString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the path to the template to use for this input.

Returns:

  • (String)

    Returns the path to the template.



94
95
96
# File 'lib/puppet/generate/type.rb', line 94

def template_path
  File.join(File.dirname(__FILE__), 'templates', 'type', "#{@format}.erb")
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the string representation of the input.

Returns:

  • (String)

    Returns the string representation of the input.



100
101
102
# File 'lib/puppet/generate/type.rb', line 100

def to_s
  @path
end

#type_nameSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Gets the expected resource type name for the input.

Returns:

  • (Symbol)

    Returns the expected resource type name for the input.



32
33
34
# File 'lib/puppet/generate/type.rb', line 32

def type_name
  File.basename(@path, '.rb').to_sym
end

#up_to_date?(outputdir) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines if the output file is up-to-date with respect to the input file.

Parameters:

  • The (String, nil)

    path to output to, or nil if determined by input

Returns:

  • (Boolean)

    Returns true if the output is up-to-date or false if not.



48
49
50
51
# File 'lib/puppet/generate/type.rb', line 48

def up_to_date?(outputdir)
  f = effective_output_path(outputdir)
  Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
end