class Subspace::Commands::Base
Public Instance Methods
confirm_overwrite(file_path)
click to toggle source
# File lib/subspace/commands/base.rb, line 50 def confirm_overwrite(file_path) return true unless File.exists? file_path answer = ask "#{file_path} already exists. Reply 'y' to overwrite: [no] " return answer.downcase.start_with? "y" end
copy(src, dest = nil)
click to toggle source
# File lib/subspace/commands/base.rb, line 43 def copy(src, dest = nil) dest ||= src return unless confirm_overwrite File.join(dest_dir, dest) FileUtils.cp File.join(template_dir, src), File.join(dest_dir, dest) say "Wrote #{dest}" end
dest_dir()
click to toggle source
# File lib/subspace/commands/base.rb, line 27 def dest_dir "config/provision" end
gem_path()
click to toggle source
# File lib/subspace/commands/base.rb, line 19 def gem_path File.expand_path '../../../..', __FILE__ end
pass_through_params()
click to toggle source
# File lib/subspace/commands/base.rb, line 56 def pass_through_params ansible_options = [] self.class::PASS_THROUGH_PARAMS.each do |param_name| x = param_name.split('-')[1..-1].map(&:upcase).join('_') hash_key = (param_name.gsub('-', '_') + (x == '' ? '' : "_#{x}")).to_sym value = @options.__hash__[hash_key] if value if param_name.length > 1 ansible_options += ["--#{param_name}", value] else ansible_options += ["-#{param_name}", value] end end end ansible_options end
playbook_dir()
click to toggle source
# File lib/subspace/commands/base.rb, line 11 def playbook_dir File.join(gem_path, 'ansible', 'playbooks') end
project_path()
click to toggle source
# File lib/subspace/commands/base.rb, line 23 def project_path Dir.pwd # TODO make sure this is correct if they for whatever reason aren't running subspace from the project root?? end
require_configuration()
click to toggle source
# File lib/subspace/commands/base.rb, line 7 def require_configuration load "config/provision.rb" end
set_subspace_version()
click to toggle source
# File lib/subspace/commands/base.rb, line 74 def set_subspace_version ENV['SUBSPACE_VERSION'] = Subspace::VERSION end
template(src, dest = nil, render_binding = nil)
click to toggle source
# File lib/subspace/commands/base.rb, line 31 def template(src, dest = nil, render_binding = nil) return unless confirm_overwrite File.join(dest_dir, dest || src) template! src, dest, render_binding say "Wrote #{dest}" end
template!(src, dest = nil, render_binding = nil)
click to toggle source
# File lib/subspace/commands/base.rb, line 37 def template!(src, dest = nil, render_binding = nil) dest ||= src template = ERB.new File.read(File.join(template_dir, "#{src}.erb")), nil, '-' File.write File.join(dest_dir, dest), template.result(render_binding || binding) end
template_dir()
click to toggle source
# File lib/subspace/commands/base.rb, line 15 def template_dir File.join(gem_path, 'template', 'provision') end