Module: Rsm::Actions

Included in:
Base
Defined in:
lib/rsm/actions.rb

Constant Summary collapse

TAR_OPTS =
{:gz => '-z', :bz2 => '-j'}.freeze

Instance Method Summary collapse

Instance Method Details

#application_rootObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rsm/actions.rb', line 5

def application_root
  unless @application_root
    @application_root = if options[:capistrano]
      "#{options[:apps_root]}/#{name}/#{options[:capistrano]}/current"
    else
      "#{options[:apps_root]}/#{name}"
    end
    @application_root = Pathname.new(@application_root)
    say "Application root: #{@application_root}" if options[:verbose]
  end
  @application_root
end

#downloaded_file(name, compressor) ⇒ Object

relative downloaded filename

name

application name

compressor

:gz or :bz2



42
43
44
# File 'lib/rsm/actions.rb', line 42

def downloaded_file(name, compressor)
  "#{name}.tar.#{compressor}"
end

#fetch_temporary_archive(name, uri, compressor) ⇒ Object

download archive form uri and temporary save it

name

application name

uri

source URI - supported by open-uri.

compressor

:gz or :bz2



50
51
52
# File 'lib/rsm/actions.rb', line 50

def fetch_temporary_archive(name, uri, compressor)
  get uri, downloaded_file(name, compressor)
end

#ruby_binaryObject



18
19
20
21
22
23
24
25
26
# File 'lib/rsm/actions.rb', line 18

def ruby_binary
  rvmrc = application_root.join(".rvmrc")
  with = if rvmrc.exist?
    File.new(rvmrc).readline.strip + " exec"
  else
    "#{Thor::Util.ruby_command} -S"
  end
  with
end

#run_ruby_binary(command, config = {}) ⇒ Object



28
29
30
# File 'lib/rsm/actions.rb', line 28

def run_ruby_binary(command, config = {})
  run(command, config.merge(:with => ruby_binary))
end

#run_with_bundler(command, config = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/rsm/actions.rb', line 32

def run_with_bundler(command, config = {})
  ruby_binary_with_bundler = "#{ruby_binary} bundle exec"
  inside application_root do
    run(command, config.merge(:with => ruby_binary_with_bundler))
  end
end

#unpack_compressed_archive(name, compressor) ⇒ Object

unpack temporary archive file

name

application name

compressor

:gz or :bz2



57
58
59
60
# File 'lib/rsm/actions.rb', line 57

def unpack_compressed_archive(name, compressor)
  opt = TAR_OPTS[compressor]
  run "tar --remove-files #{opt} -xf #{downloaded_file(name, compressor)}"
end