Module: Inploy::DSL
- Included in:
- Deploy
- Defined in:
- lib/inploy/dsl.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #callback(name) ⇒ Object
- #create_folder(path) ⇒ Object
- #create_folders(*folders) ⇒ Object
- #file_exists?(file) ⇒ Boolean
- #load_module(filename) ⇒ Object
- #log(command) ⇒ Object
- #login_shell_wrap(cmd) ⇒ Object
- #rake(command) ⇒ Object
- #rake_if_included(command) ⇒ Object
- #remote_run(command) ⇒ Object
- #ruby_if_exists(file, opts) ⇒ Object
- #run(command, disable_sudo = false) ⇒ Object
- #secure_copy(src, dest) ⇒ Object
- #sudo_if_should ⇒ Object
- #using_bundler? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
13 14 15 |
# File 'lib/inploy/dsl.rb', line 13 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#callback(name) ⇒ Object
17 18 19 20 |
# File 'lib/inploy/dsl.rb', line 17 def callback(name) instance_variable = instance_variable_get("@#{name.to_s}") instance_eval(&instance_variable) unless instance_variable.nil? end |
#create_folder(path) ⇒ Object
22 23 24 |
# File 'lib/inploy/dsl.rb', line 22 def create_folder(path) run "mkdir -p #{path}" end |
#create_folders(*folders) ⇒ Object
26 27 28 |
# File 'lib/inploy/dsl.rb', line 26 def create_folders(*folders) folders.each { |folder| create_folder folder } end |
#file_exists?(file) ⇒ Boolean
87 88 89 |
# File 'lib/inploy/dsl.rb', line 87 def file_exists?(file) File.exists? file end |
#load_module(filename) ⇒ Object
30 31 32 33 |
# File 'lib/inploy/dsl.rb', line 30 def load_module(filename) require "inploy/#{filename}" extend eval(filename.split("/").map { |word| camelize(word) }.join("::")) end |
#log(command) ⇒ Object
35 36 37 |
# File 'lib/inploy/dsl.rb', line 35 def log(command) puts "Inploy => #{command}" end |
#login_shell_wrap(cmd) ⇒ Object
76 77 78 |
# File 'lib/inploy/dsl.rb', line 76 def login_shell_wrap(cmd) login_shell ? "\"bash -l -c '#{cmd}'\"" : "'#{cmd}'" end |
#rake(command) ⇒ Object
39 40 41 |
# File 'lib/inploy/dsl.rb', line 39 def rake(command) run "rake #{command}" end |
#rake_if_included(command) ⇒ Object
43 44 45 |
# File 'lib/inploy/dsl.rb', line 43 def rake_if_included(command) rake command if tasks.include?("rake #{command.split[0]}") end |
#remote_run(command) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/inploy/dsl.rb', line 69 def remote_run(command) port_opts = port ? "-p #{port} " : '' hosts.each do |host| run "ssh #{ssh_opts} #{port_opts}#{user}@#{host} #{login_shell_wrap(command)}", true end end |
#ruby_if_exists(file, opts) ⇒ Object
47 48 49 |
# File 'lib/inploy/dsl.rb', line 47 def ruby_if_exists(file, opts) run "ruby #{file} #{opts[:params]}" if file_exists?(file) end |
#run(command, disable_sudo = false) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/inploy/dsl.rb', line 59 def run(command, disable_sudo = false) log command if disable_sudo Kernel.system command else Kernel.system "#{sudo_if_should}#{command}" end end |
#secure_copy(src, dest) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/inploy/dsl.rb', line 80 def secure_copy(src, dest) unless file_exists?(dest) log "mv #{src} #{dest}" FileUtils.cp src, dest end end |
#sudo_if_should ⇒ Object
51 52 53 |
# File 'lib/inploy/dsl.rb', line 51 def sudo_if_should @sudo ? 'sudo ' : '' end |
#using_bundler? ⇒ Boolean
55 56 57 |
# File 'lib/inploy/dsl.rb', line 55 def using_bundler? file_exists?("Gemfile") end |