class Warg::Script::Template
Constants
- INTERPOLATION_REGEXP
- MISSING
Attributes
content[R]
Public Class Methods
find(relative_script_path, fail_if_missing: true)
click to toggle source
# File lib/warg.rb, line 2048 def self.find(relative_script_path, fail_if_missing: true) extension = File.extname(relative_script_path) relative_paths = [relative_script_path] if extension.empty? relative_paths << "#{relative_script_path}.sh" else relative_paths << relative_script_path.chomp(extension) end paths_checked = [] script_path = Warg.search_paths.inject(nil) do |path, directory| relative_paths.each do |relative_path| target_path = directory.join("scripts", relative_path) paths_checked << target_path if target_path.exist? path = target_path end end if path break path end end if script_path new(script_path) elsif fail_if_missing raise <<~ERROR ScriptNotFoundError: Could not find `#{relative_script_path}' Looked in: #{paths_checked.join("\n")} ERROR else MISSING end end
new(file_path)
click to toggle source
# File lib/warg.rb, line 2098 def initialize(file_path) @path = file_path @content = @path.read end
Public Instance Methods
compile(interpolations)
click to toggle source
# File lib/warg.rb, line 2103 def compile(interpolations) @content.gsub(INTERPOLATION_REGEXP) do |match| if interpolations.key?($1) interpolations[$1] else $stderr.puts "[WARN] `#{$1}' is not defined in interpolations or context variables" $stderr.puts "[WARN] leaving interpolation `#{match}' as is" match end end end