class Puppet::Generate::Type::Input
Represents an input to the type generator
Attributes
Gets the format to use for generating the output file.
Gets the path to the input.
Public Class Methods
Initializes an input. @param base [String] The base path where the input is located. @param path [String] The path to the input file. @param format [Symbol] The format to use for generation. @return [void]
# File lib/puppet/generate/type.rb 23 def initialize(base, path, format) 24 @base = base 25 @path = path 26 self.format = format 27 end
Determines if the given format is supported @param format [Symbol] The format to use for generation. @return [Boolean] Returns true if the format is supported or false if not.
# File lib/puppet/generate/type.rb 106 def self.supported_format?(format) 107 [:pcore].include?(format) 108 end
Public Instance Methods
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. @param [String, nil] The outputdirectory to use, or nil if to be determined by this Input
# File lib/puppet/generate/type.rb 87 def effective_output_path(outputdir) 88 outputdir ? File.join(outputdir, output_name) : output_path 89 end
Sets the format to use for this input. @param format [Symbol] The format to use for generation. @return [Symbol] Returns the new format.
# File lib/puppet/generate/type.rb 38 def format=(format) 39 format = format.to_sym 40 raise _("unsupported format '%{format}'.") % { format: format } unless self.class.supported_format?(format) 41 @format = format 42 end
Gets the filename of the output file. @return [String] Returns the name to the output file.
# File lib/puppet/generate/type.rb 54 def output_name 55 @output_name ||= 56 case @format 57 when :pcore 58 "#{File.basename(@path, '.rb')}.pp" 59 else 60 raise _("unsupported format '%{format}'.") % { format: @format } 61 end 62 end
Gets the path to the output file. @return [String] Returns the path to the output file.
# File lib/puppet/generate/type.rb 66 def output_path 67 @output_path ||= 68 case @format 69 when :pcore 70 File.join(@base, 'pcore', 'types', output_name) 71 else 72 raise _("unsupported format '%{format}'.") % { format: @format } 73 end 74 end
Sets the path to the output file. @param path [String] The new path to the output file. @return [String] Returns the new path to the output file.
# File lib/puppet/generate/type.rb 79 def output_path=(path) 80 @output_path = path 81 end
Gets the path to the template to use for this input. @return [String] Returns the path to the template.
# File lib/puppet/generate/type.rb 93 def template_path 94 File.join(File.dirname(__FILE__), 'templates', 'type', "#{@format}.erb") 95 end
Gets the string representation of the input. @return [String] Returns the string representation of the input.
# File lib/puppet/generate/type.rb 99 def to_s 100 @path 101 end
Gets the expected resource type name for the input. @return [Symbol] Returns the expected resource type name for the input.
# File lib/puppet/generate/type.rb 31 def type_name 32 File.basename(@path, '.rb').to_sym 33 end
Determines if the output file is up-to-date with respect to the input file. @param [String, nil] The path to output to, or nil if determined by input @return [Boolean] Returns true if the output is up-to-date or false if not.
# File lib/puppet/generate/type.rb 47 def up_to_date?(outputdir) 48 f = effective_output_path(outputdir) 49 Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0 50 end