class Builtins::Init
Constants
- DEFAULT_TEMPLATE_NAME
- OPS_YML
- OPS_YML_TEMPLATE
- TEMPLATE_DIR
Public Class Methods
description()
click to toggle source
# File lib/builtins/init.rb, line 16 def description "creates an ops.yml file from a template" end
Public Instance Methods
run()
click to toggle source
# File lib/builtins/init.rb, line 21 def run if File.exist?(OPS_YML) Output.error("File '#{OPS_YML} exists; not initializing.") else Output.out("Creating '#{OPS_YML} from template...") FileUtils.cp(template_path, OPS_YML) end rescue SystemCallError Output.error(template_not_found_message) exit 1 end
Private Instance Methods
builtin_template_path()
click to toggle source
# File lib/builtins/init.rb, line 45 def builtin_template_path format(OPS_YML_TEMPLATE, template_name: template_name || DEFAULT_TEMPLATE_NAME) end
template_name()
click to toggle source
# File lib/builtins/init.rb, line 35 def template_name @args[0] end
template_name_list()
click to toggle source
# File lib/builtins/init.rb, line 49 def template_name_list @template_name_list ||= Dir.entries(TEMPLATE_DIR).map do |name| name.match(/^([^.]*).template.yml/)&.captures&.first end.compact end
template_not_found_message()
click to toggle source
# File lib/builtins/init.rb, line 55 def template_not_found_message <<~MESSAGE Template '#{template_path} does not exist. \nValid template names are: - #{template_name_list.join("\n - ")}\n MESSAGE end
template_path()
click to toggle source
# File lib/builtins/init.rb, line 39 def template_path return template_name if template_name && File.exist?(template_name) builtin_template_path end