Module: PDK::Module::TemplateDir
- Defined in:
- lib/pdk/module/template_dir.rb,
lib/pdk/module/template_dir/git.rb,
lib/pdk/module/template_dir/base.rb,
lib/pdk/module/template_dir/local.rb
Defined Under Namespace
Class Method Summary collapse
-
.files_in_template(dirs) ⇒ Hash{String=>String}
Get a list of template files in the template directory.
- .moduleroot_dir(template_root_dir) ⇒ Object
- .moduleroot_init(template_root_dir) ⇒ Object
-
.validate_module_template!(template_root_dir) ⇒ void
Validate the content of the template directory.
-
.with(uri, module_metadata = {}, init = false) {|self| ... } ⇒ Object
Creates a TemplateDir object with the path or URL to the template and the block of code to run to be run while the template is available.
Class Method Details
.files_in_template(dirs) ⇒ Hash{String=>String}
Get a list of template files in the template directory.
value locations.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pdk/module/template_dir.rb', line 97 def self.files_in_template(dirs) temp_paths = [] dirlocs = [] dirs.each do |dir| raise ArgumentError, _("The directory '%{dir}' doesn't exist") % { dir: dir } unless PDK::Util::Filesystem.directory?(dir) temp_paths += PDK::Util::Filesystem.glob(File.join(dir, '**', '*'), File::FNM_DOTMATCH).select do |template_path| if PDK::Util::Filesystem.file?(template_path) && !PDK::Util::Filesystem.symlink?(template_path) dirlocs << dir end end temp_paths.map do |template_path| template_path.sub!(%r{\A#{Regexp.escape(dir)}#{Regexp.escape(File::SEPARATOR)}}, '') end end Hash[temp_paths.zip dirlocs] end |
.moduleroot_dir(template_root_dir) ⇒ Object
50 51 52 |
# File 'lib/pdk/module/template_dir.rb', line 50 def self.moduleroot_dir(template_root_dir) File.join(template_root_dir, 'moduleroot') end |
.moduleroot_init(template_root_dir) ⇒ Object
54 55 56 |
# File 'lib/pdk/module/template_dir.rb', line 54 def self.moduleroot_init(template_root_dir) File.join(template_root_dir, 'moduleroot_init') end |
.validate_module_template!(template_root_dir) ⇒ void
This method returns an undefined value.
Validate the content of the template directory.
a directory called ‘moduleroot’.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pdk/module/template_dir.rb', line 67 def self.validate_module_template!(template_root_dir) # rubocop:disable Style/GuardClause unless PDK::Util::Filesystem.directory?(template_root_dir) require 'pdk/util' if PDK::Util.package_install? && PDK::Util::Filesystem.fnmatch?(File.join(PDK::Util.package_cachedir, '*'), template_root_dir) raise ArgumentError, _('The built-in template has substantially changed. Please run "pdk convert" on your module to continue.') else raise ArgumentError, _("The specified template '%{path}' is not a directory.") % { path: template_root_dir } end end unless PDK::Util::Filesystem.directory?(moduleroot_dir(template_root_dir)) raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot/' directory.") % { path: template_root_dir } end unless PDK::Util::Filesystem.directory?(moduleroot_init(template_root_dir)) # rubocop:disable Metrics/LineLength raise ArgumentError, _("The template at '%{path}' does not contain a 'moduleroot_init/' directory, which indicates you are using an older style of template. Before continuing please use the --template-url flag when running the pdk new commands to pass a new style template.") % { path: template_root_dir } # rubocop:enable Metrics/LineLength end # rubocop:enable Style/GuardClause end |
.with(uri, module_metadata = {}, init = false) {|self| ... } ⇒ Object
Creates a TemplateDir object with the path or URL to the template and the block of code to run to be run while the template is available.
The template directory is only guaranteed to be available on disk within the scope of the block passed to this method.
template or a URI to a git repository. Defaults to an empty Hash. the template available on disk.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pdk/module/template_dir.rb', line 33 def self.with(uri, = {}, init = false) unless block_given? raise ArgumentError, _('%{class_name}.with must be passed a block.') % { class_name: name } end unless uri.is_a? PDK::Util::TemplateURI raise ArgumentError, _('%{class_name}.with must be passed a PDK::Util::TemplateURI, got a %{uri_type}') % { uri_type: uri.class, class_name: name } end if PDK::Util::Git.repo?(uri.) require 'pdk/module/template_dir/git' PDK::Module::TemplateDir::Git.new(uri, , init) { |value| yield value } else require 'pdk/module/template_dir/local' PDK::Module::TemplateDir::Local.new(uri, , init) { |value| yield value } end end |