module Ore::Template::Interpolations

Handles the expansion of paths and substitution of path keywords. The following keywords are supported:

Protected Instance Methods

interpolate(path) click to toggle source

Expands the given path by substituting the interpolation keywords for the related instance variables.

@param [String] path

The path to expand.

@return [String]

The expanded path.

@example Assuming ‘@project_dir` contains `my_project`.

interpolate("lib/[project_dir].rb")
# => "lib/my_project.rb"

@example Assuming ‘@namespace_path` contains `my/project`.

interpolate("spec/[namespace_path]_spec.rb")
# => "spec/my/project_spec.rb"
# File lib/ore/template/interpolations.rb, line 50
def interpolate(path)
  dirs = path.split(File::SEPARATOR)

  dirs.each do |dir|
    dir.gsub!(/(\[[a-z_]+\])/) do |capture|
      keyword = capture[1..-2]

      if @@keywords.include?(keyword)
        instance_variable_get("@#{keyword}")
      else
        capture
      end
    end
  end

  return File.join(dirs.reject { |dir| dir.empty? })
end