Module: EasyType::PathHelpers
- Included in:
- Generators::Base
- Defined in:
- lib/easy_type/path_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#attribute_path ⇒ Object
Give the full path name of a ruby file describing the parameter.
-
#create_directory(path) ⇒ Object
Create a directory and notify user of it’s creation.
-
#create_source(name, destination) ⇒ Object
Create a source file based on a ERB template.
-
#modulepath ⇒ Object
Returns the system wide module path.
-
#name_attribute_path ⇒ Object
Give the full path name of a ruby file describing the name parameter.
-
#provider_directory ⇒ Object
Return the name of the provider directory.
-
#provider_path ⇒ Object
Return the full path name of a ruby file describing the provider.
-
#puppet_lib ⇒ Object
Return the puppet library path of the current custom type.
-
#puppet_lib? ⇒ Boolean
Returns a true if the expected puppet library path exists.
-
#save_file(path, content) ⇒ Object
Save some content to a file.
-
#shared_attribute_path ⇒ Object
Give the full path name of a ruby file describing the shared property.
-
#template_path(template) ⇒ Object
Search the modulepath for where easy_type’s template’s are stored.
-
#type_attribute_directory ⇒ Object
Give the directory name where the type definitions reside.
-
#type_directory ⇒ Object
return the directory where the types reside.
-
#type_path ⇒ Object
Give the full path name of a ruby file containing the type definition.
-
#type_shared_directory ⇒ Object
Return the directory name where the shared type definitions reside.
-
#write_file(path, content) ⇒ Object
Write the content to a file.
Class Method Details
.included(parent) ⇒ Object
5 6 7 |
# File 'lib/easy_type/path_helpers.rb', line 5 def self.included(parent) parent.extend(PathHelpers) end |
Instance Method Details
#attribute_path ⇒ Object
Give the full path name of a ruby file describing the parameter
64 65 66 |
# File 'lib/easy_type/path_helpers.rb', line 64 def attribute_path type_attribute_directory + "#{@attribute_name}.rb" end |
#create_directory(path) ⇒ Object
Create a directory and notify user of it’s creation
112 113 114 115 116 117 |
# File 'lib/easy_type/path_helpers.rb', line 112 def create_directory path unless File.exists?(path) FileUtils::mkdir_p path Puppet.notice "Created directory #{path}" end end |
#create_source(name, destination) ⇒ Object
Create a source file based on a ERB template
137 138 139 140 141 142 143 |
# File 'lib/easy_type/path_helpers.rb', line 137 def create_source(name, destination) template = File.read("#{template_path(name)}/easy_type/templates/#{name}") content = ERB.new(template, nil, '-').result(binding) write_file(destination, content) rescue SyntaxError fail "Error in erb template #{name}" end |
#modulepath ⇒ Object
Returns the system wide module path
99 100 101 102 103 104 105 106 |
# File 'lib/easy_type/path_helpers.rb', line 99 def modulepath env = Puppet.lookup(:environments).get(Puppet[:environment]) if env.modulepath == [] @modulepath ||= ['..'] else @modulepath ||= env.modulepath end end |
#name_attribute_path ⇒ Object
Give the full path name of a ruby file describing the name parameter
57 58 59 |
# File 'lib/easy_type/path_helpers.rb', line 57 def name_attribute_path type_attribute_directory + "#{@namevar}.rb" end |
#provider_directory ⇒ Object
Return the name of the provider directory
36 37 38 |
# File 'lib/easy_type/path_helpers.rb', line 36 def provider_directory Pathname.new(puppet_lib) + 'provider' + @name end |
#provider_path ⇒ Object
Return the full path name of a ruby file describing the provider
43 44 45 |
# File 'lib/easy_type/path_helpers.rb', line 43 def provider_path provider_directory + "#{@provider}.rb" end |
#puppet_lib ⇒ Object
Return the puppet library path of the current custom type
85 86 87 |
# File 'lib/easy_type/path_helpers.rb', line 85 def puppet_lib File.('./lib/puppet') end |
#puppet_lib? ⇒ Boolean
Returns a true if the expected puppet library path exists
92 93 94 |
# File 'lib/easy_type/path_helpers.rb', line 92 def puppet_lib? File.exists?(puppet_lib) end |
#save_file(path, content) ⇒ Object
Save some content to a file
148 149 150 151 152 |
# File 'lib/easy_type/path_helpers.rb', line 148 def save_file(path, content) File.open(path, 'w') do |f| f.write content end end |
#shared_attribute_path ⇒ Object
Give the full path name of a ruby file describing the shared property
71 72 73 |
# File 'lib/easy_type/path_helpers.rb', line 71 def shared_attribute_path type_shared_directory + "#{@attribute_name}.rb" end |
#template_path(template) ⇒ Object
Search the modulepath for where easy_type’s template’s are stored
12 13 14 15 16 17 |
# File 'lib/easy_type/path_helpers.rb', line 12 def template_path(template) modulepath.each do | path| return path if File.exists?("#{path}/easy_type/templates/#{template}") end fail "Template #{template} not found in modulepath #{modulepath}" end |
#type_attribute_directory ⇒ Object
Give the directory name where the type definitions reside
78 79 80 |
# File 'lib/easy_type/path_helpers.rb', line 78 def type_attribute_directory Pathname.new(puppet_lib) + 'type' + @name end |
#type_directory ⇒ Object
return the directory where the types reside
22 23 24 |
# File 'lib/easy_type/path_helpers.rb', line 22 def type_directory Pathname.new(puppet_lib) + 'type' end |
#type_path ⇒ Object
Give the full path name of a ruby file containing the type definition
29 30 31 |
# File 'lib/easy_type/path_helpers.rb', line 29 def type_path type_directory + "#{@name}.rb" end |
#type_shared_directory ⇒ Object
Return the directory name where the shared type definitions reside
50 51 52 |
# File 'lib/easy_type/path_helpers.rb', line 50 def type_shared_directory Pathname.new(puppet_lib) + 'type' + 'shared' end |
#write_file(path, content) ⇒ Object
Write the content to a file. If the file exists, it will not be overwritten unless the –force option is set. The user will be notified of the creation of the file
124 125 126 127 128 129 130 131 132 |
# File 'lib/easy_type/path_helpers.rb', line 124 def write_file(path, content) file_exists = File.exists?(path) if file_exists and not @force fail "File #{path} already exists. Not overwritten. Use --force to overwrite" end save_file(path,content) = file_exists ? "File #{path} overwriten with new content" : "File #{path} created" Puppet.notice end |