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

Class Method Details

.included(base) ⇒ Object



15
16
17
# File 'lib/inploy/dsl.rb', line 15

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#callback(name) ⇒ Object



19
20
21
22
# File 'lib/inploy/dsl.rb', line 19

def callback(name)
  instance_variable = instance_variable_get("@#{name.to_s}")
  instance_eval(&instance_variable) unless instance_variable.nil?
end

#create_folder(path) ⇒ Object



24
25
26
# File 'lib/inploy/dsl.rb', line 24

def create_folder(path)
  run "mkdir -p #{path}"
end

#create_folders(*folders) ⇒ Object



28
29
30
# File 'lib/inploy/dsl.rb', line 28

def create_folders(*folders)
  folders.each { |folder| create_folder folder }
end

#file_exists?(file) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/inploy/dsl.rb', line 94

def file_exists?(file)
  File.exists? file
end

#load_module(filename) ⇒ Object



32
33
34
35
# File 'lib/inploy/dsl.rb', line 32

def load_module(filename)
  require "inploy/#{filename}"
  extend eval(filename.split("/").map { |word| camelize(word) }.join("::"))
end

#login_shell_wrap(cmd) ⇒ Object



83
84
85
# File 'lib/inploy/dsl.rb', line 83

def (cmd)
   ? "\"bash -l -c '#{cmd}'\"" : "'#{cmd}'"
end

#rake(command) ⇒ Object



37
38
39
# File 'lib/inploy/dsl.rb', line 37

def rake(command)
  run "rake #{command}"
end

#rake_if_included(command) ⇒ Object



41
42
43
# File 'lib/inploy/dsl.rb', line 41

def rake_if_included(command)
  rake command if tasks.include?("rake #{command.split[0]}")
end

#remote_run(command) ⇒ Object



76
77
78
79
80
81
# File 'lib/inploy/dsl.rb', line 76

def remote_run(command)
  port_opts = port ? "-p #{port} " : ''
  hosts.each do |host|
    run "ssh #{ssh_opts} #{port_opts}#{user}@#{host} #{(command)}", true
  end
end

#ruby_if_exists(file, opts) ⇒ Object



45
46
47
# File 'lib/inploy/dsl.rb', line 45

def ruby_if_exists(file, opts)
  run "ruby #{file} #{opts[:params]}" if file_exists?(file)
end

#run(command, disable_sudo = false) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/inploy/dsl.rb', line 64

def run(command, disable_sudo = false)
  say command

  Bundler.with_clean_env do
    if disable_sudo
      Kernel.system command
    else
      Kernel.system "#{sudo_if_should}#{command}"
    end
  end
end

#say(message) {|output| ... } ⇒ Object

Yields:

  • (output)


57
58
59
60
61
62
# File 'lib/inploy/dsl.rb', line 57

def say(message)
  puts "Inploy => #{message}"
  output = []
  yield output if block_given?
  output.each {|o| puts o if o =~ /\S/ }
end

#secure_copy(src, dest) ⇒ Object



87
88
89
90
91
92
# File 'lib/inploy/dsl.rb', line 87

def secure_copy(src, dest)
  unless file_exists?(dest)
    say "cp #{src} #{dest}"
    FileUtils.cp src, dest
  end
end

#sudo_if_shouldObject



49
50
51
# File 'lib/inploy/dsl.rb', line 49

def sudo_if_should
  @sudo ? 'sudo ' : ''
end

#using_bundler?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/inploy/dsl.rb', line 53

def using_bundler?
  file_exists?("Gemfile")
end