Class: Puppet::Generate::Type::Input Private
- 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
-
#format ⇒ Object
private
Gets the format to use for generating the output file.
-
#path ⇒ Object
readonly
private
Gets the path to the input.
Class Method Summary collapse
-
.supported_format?(format) ⇒ Boolean
private
Determines if the given format is supported.
Instance Method Summary collapse
-
#effective_output_path(outputdir) ⇒ Object
private
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.
-
#initialize(base, path, format) ⇒ void
constructor
private
Initializes an input.
-
#output_name ⇒ String
private
Gets the filename of the output file.
-
#output_path ⇒ String
private
Gets the path to the output file.
-
#output_path=(path) ⇒ String
private
Sets the path to the output file.
-
#template_path ⇒ String
private
Gets the path to the template to use for this input.
-
#to_s ⇒ String
private
Gets the string representation of the input.
-
#type_name ⇒ Symbol
private
Gets the expected resource type name for the input.
-
#up_to_date?(outputdir) ⇒ Boolean
private
Determines if the output file is up-to-date with respect to the input file.
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.
23 24 25 26 27 |
# File 'lib/puppet/generate/type.rb', line 23 def initialize(base, path, format) @base = base @path = path self.format = format end |
Instance Attribute Details
#format ⇒ 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.
Gets the format to use for generating the output file.
16 17 18 |
# File 'lib/puppet/generate/type.rb', line 16 def format @format end |
#path ⇒ Object (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.
13 14 15 |
# File 'lib/puppet/generate/type.rb', line 13 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
106 107 108 |
# File 'lib/puppet/generate/type.rb', line 106 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.
87 88 89 |
# File 'lib/puppet/generate/type.rb', line 87 def effective_output_path(outputdir) outputdir ? File.join(outputdir, output_name) : output_path end |
#output_name ⇒ 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.
Gets the filename of the output file.
54 55 56 57 58 59 60 61 62 |
# File 'lib/puppet/generate/type.rb', line 54 def output_name @output_name ||= case @format when :pcore "#{File.basename(@path, '.rb')}.pp" else raise _("unsupported format '%{format}'.") % { format: @format } end end |
#output_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.
Gets the path to the output file.
66 67 68 69 70 71 72 73 74 |
# File 'lib/puppet/generate/type.rb', line 66 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.
79 80 81 |
# File 'lib/puppet/generate/type.rb', line 79 def output_path=(path) @output_path = path end |
#template_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.
Gets the path to the template to use for this input.
93 94 95 |
# File 'lib/puppet/generate/type.rb', line 93 def template_path File.join(File.dirname(__FILE__), 'templates', 'type', "#{@format}.erb") end |
#to_s ⇒ 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.
Gets the string representation of the input.
99 100 101 |
# File 'lib/puppet/generate/type.rb', line 99 def to_s @path end |
#type_name ⇒ Symbol
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.
31 32 33 |
# File 'lib/puppet/generate/type.rb', line 31 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.
47 48 49 50 |
# File 'lib/puppet/generate/type.rb', line 47 def up_to_date?(outputdir) f = effective_output_path(outputdir) Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0 end |