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 24 def initialize(base, path, format) 25 @base = base 26 @path = path 27 self.format = format 28 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 107 def self.supported_format?(format) 108 [:pcore].include?(format) 109 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 88 def effective_output_path(outputdir) 89 outputdir ? File.join(outputdir, output_name) : output_path 90 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 39 def format=(format) 40 format = format.to_sym 41 raise _("unsupported format '%{format}'.") % { format: format } unless self.class.supported_format?(format) 42 @format = format 43 end
Gets the filename of the output file. @return [String] Returns the name to the output file.
# File lib/puppet/generate/type.rb 55 def output_name 56 @output_name ||= 57 case @format 58 when :pcore 59 "#{File.basename(@path, '.rb')}.pp" 60 else 61 raise _("unsupported format '%{format}'.") % { format: @format } 62 end 63 end
Gets the path to the output file. @return [String] Returns the path to the output file.
# File lib/puppet/generate/type.rb 67 def output_path 68 @output_path ||= 69 case @format 70 when :pcore 71 File.join(@base, 'pcore', 'types', output_name) 72 else 73 raise _("unsupported format '%{format}'.") % { format: @format } 74 end 75 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 80 def output_path=(path) 81 @output_path = path 82 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 94 def template_path 95 File.join(File.dirname(__FILE__), 'templates', 'type', "#{@format}.erb") 96 end
Gets the string representation of the input. @return [String] Returns the string representation of the input.
# File lib/puppet/generate/type.rb 100 def to_s 101 @path 102 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 32 def type_name 33 File.basename(@path, '.rb').to_sym 34 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 48 def up_to_date?(outputdir) 49 f = effective_output_path(outputdir) 50 Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0 51 end