Top Level Namespace

Defined Under Namespace

Modules: Kernel, Minestrone Classes: String

Instance Method Summary collapse

Instance Method Details

#_cset(name, *args, &block) ⇒ Object



10
11
12
13
14
# File 'lib/minestrone/recipes/deploy.rb', line 10

def _cset(name, *args, &block)
  unless exists?(name)
    set(name, *args, &block)
  end
end

#depend(location, type, *args) ⇒ Object

Auxiliary helper method for the ‘deploy:check’ task. Lets you set up your own dependencies.



96
97
98
99
100
101
102
# File 'lib/minestrone/recipes/deploy.rb', line 96

def depend(location, type, *args)
  deps = fetch(:dependencies, {})
  deps[location] ||= {}
  deps[location][type] ||= []
  deps[location][type] << args
  set :dependencies, deps
end

#parse_manifest(str) ⇒ Object

Parses manifest and returns array of uncompressed and compressed asset filenames with and without digests “Intelligently” determines format of string - supports YAML and JSON



27
28
29
30
31
# File 'lib/minestrone/recipes/deploy/assets.rb', line 27

def parse_manifest(str)
  assets_hash = str[0,1] == '{' ? JSON.parse(str)['assets'] : YAML.load(str)

  assets_hash.to_a.flatten.map {|a| [a, "#{a}.gz"] }.flatten
end

#run_locally(cmd) ⇒ Object

Logs the command then executes it locally. Returns the command output as a string.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/minestrone/recipes/deploy.rb', line 113

def run_locally(cmd)
  if dry_run
    return logger.debug "executing locally: #{cmd.inspect}"
  end

  logger.trace "executing locally: #{cmd.inspect}" if logger
  output_on_stdout = nil

  elapsed = Benchmark.realtime do
    output_on_stdout = `#{cmd}`
  end

  if $?.to_i > 0 # $? is command exit code (posix style)
    raise Minestrone::LocalArgumentError, "Command #{cmd} returned status code #{$?}"
  end

  logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
  output_on_stdout
end

#scm_defaultObject

Checks known version control directories to set the version control in-use. If a .git directory exists in the project, it will set the :scm variable to :git. If no supported directory is found, it will default to :none.



91
92
93
# File 'lib/minestrone/recipes/deploy.rb', line 91

def scm_default
  File.exist?('.git') ? :git : :none
end

#shared_manifest_pathObject



21
22
23
# File 'lib/minestrone/recipes/deploy/assets.rb', line 21

def shared_manifest_path
  @shared_manifest_path ||= capture("ls #{shared_path.shellescape}/#{shared_assets_prefix}/#{asset_manifest_prefix}*").strip
end

#try_runner(*args) ⇒ Object

Same as sudo, but tries sudo with :as set to the value of the :runner variable (which defaults to “app”).



168
169
170
171
172
# File 'lib/minestrone/recipes/deploy.rb', line 168

def try_runner(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  args << options.merge(:as => fetch(:runner, "app"))
  try_sudo(*args)
end

#try_sudo(*args) ⇒ Object

If a command is given, this will try to execute the given command, as described below. Otherwise, it will return a string for use in embedding in another command, for executing that command as described below.

If :run_method is :sudo (or :use_sudo is true), this executes the given command via sudo. Otherwise is uses run. If :as is given as a key, it will be passed as the user to sudo as, if using sudo. If the :as key is not given, it will default to whatever the value of the :admin_runner variable is, which (by default) is unset.

THUS, if you want to try to run something via sudo, and what to use the root user, you’d just to try_sudo(‘something’). If you wanted to try_sudo as someone else, you’d just do try_sudo(‘something’, :as => “bob”). If you always wanted sudo to run as a particular user, you could do set(:admin_runner, “bob”).

Raises:

  • (ArgumentError)


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/minestrone/recipes/deploy.rb', line 150

def try_sudo(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  command = args.shift
  raise ArgumentError, "too many arguments" if args.any?

  as = options.fetch(:as, fetch(:admin_runner, nil))
  via = fetch(:run_method, :sudo)

  if command
    invoke_command(command, :via => via, :as => as)
  elsif via == :sudo
    sudo(:as => as)
  else
    ""
  end
end

#with_env(name, value) ⇒ Object

Temporarily sets an environment variable, yields to a block, and restores the value when it is done.



105
106
107
108
109
110
# File 'lib/minestrone/recipes/deploy.rb', line 105

def with_env(name, value)
  saved, ENV[name] = ENV[name], value
  yield
ensure
  ENV[name] = saved
end