Class: Puppet::Generate::Type::Input
- Defined in:
- lib/puppet/generate/type.rb
Overview
Represents an input to the type generator
Instance Attribute Summary collapse
-
#format ⇒ Object
Gets the format to use for generating the output file.
-
#path ⇒ Object
readonly
Gets the path to the input.
Class Method Summary collapse
-
.supported_format?(format) ⇒ Boolean
Determines if the given format is supported.
Instance Method Summary collapse
-
#effective_output_path(outputdir) ⇒ Object
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
Initializes an input.
-
#output_name ⇒ String
Gets the filename of the output file.
-
#output_path ⇒ String
Gets the path to the output file.
-
#output_path=(path) ⇒ String
Sets the path to the output file.
-
#template_path ⇒ String
Gets the path to the template to use for this input.
-
#to_s ⇒ String
Gets the string representation of the input.
-
#type_name ⇒ Symbol
Gets the expected resource type name for the input.
-
#up_to_date?(outputdir) ⇒ Boolean
Determines if the output file is up-to-date with respect to the input file.
Constructor Details
#initialize(base, path, format) ⇒ void
Initializes an input.
25 26 27 28 29 |
# File 'lib/puppet/generate/type.rb', line 25 def initialize(base, path, format) @base = base @path = path self.format = format end |
Instance Attribute Details
#format ⇒ Object
Gets the format to use for generating the output file.
18 19 20 |
# File 'lib/puppet/generate/type.rb', line 18 def format @format end |
#path ⇒ Object (readonly)
Gets the path to the input.
15 16 17 |
# File 'lib/puppet/generate/type.rb', line 15 def path @path end |
Class Method Details
.supported_format?(format) ⇒ Boolean
Determines if the given format is supported
109 110 111 |
# File 'lib/puppet/generate/type.rb', line 109 def self.supported_format?(format) [:pcore].include?(format) end |
Instance Method Details
#effective_output_path(outputdir) ⇒ Object
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.
90 91 92 |
# File 'lib/puppet/generate/type.rb', line 90 def effective_output_path(outputdir) outputdir ? File.join(outputdir, output_name) : output_path end |
#output_name ⇒ String
Gets the filename of the output file.
57 58 59 60 61 62 63 64 65 |
# File 'lib/puppet/generate/type.rb', line 57 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
Gets the path to the output file.
69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/generate/type.rb', line 69 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
Sets the path to the output file.
82 83 84 |
# File 'lib/puppet/generate/type.rb', line 82 def output_path=(path) @output_path = path end |
#template_path ⇒ String
Gets the path to the template to use for this input.
96 97 98 |
# File 'lib/puppet/generate/type.rb', line 96 def template_path File.join(File.dirname(__FILE__), 'templates', 'type', "#{@format}.erb") end |
#to_s ⇒ String
Gets the string representation of the input.
102 103 104 |
# File 'lib/puppet/generate/type.rb', line 102 def to_s @path end |
#type_name ⇒ Symbol
Gets the expected resource type name for the input.
33 34 35 |
# File 'lib/puppet/generate/type.rb', line 33 def type_name File.basename(@path, '.rb').to_sym end |
#up_to_date?(outputdir) ⇒ Boolean
Determines if the output file is up-to-date with respect to the input file.
50 51 52 53 |
# File 'lib/puppet/generate/type.rb', line 50 def up_to_date?(outputdir) f = effective_output_path(outputdir) Puppet::FileSystem.exist?(f) && (Puppet::FileSystem.stat(@path) <=> Puppet::FileSystem.stat(f)) <= 0 end |