class WWTD::Run
Constants
- SCRIPT_SECTIONS
Attributes
config[R]
env[R]
lock[R]
switch[R]
Public Class Methods
new(config, env, lock)
click to toggle source
# File lib/wwtd/run.rb, line 6 def initialize(config, env, lock) @config, @env, @lock = config, env, lock add_env_from_config @switch = build_switch_statement end
Public Instance Methods
env_and_command_for_section(key)
click to toggle source
internal api
# File lib/wwtd/run.rb, line 26 def env_and_command_for_section(key) if command = config[key] command = [command] unless Array === command command = command.map { |cmd| "#{switch}#{cmd}" }.join(" && ") [env, command] elsif key == "script" command = (wants_bundle? ? "#{switch}bundle exec rake" : "#{switch}rake") [env, command] end end
execute() { |:start, config| ... }
click to toggle source
# File lib/wwtd/run.rb, line 12 def execute state = if Ruby.available?(config["rvm"]) yield(:start, config) success? ? :success : :failure else :missing_ruby_version end yield(state, config) [state, config] end
Private Instance Methods
add_env_from_config()
click to toggle source
# File lib/wwtd/run.rb, line 74 def add_env_from_config Shellwords.split(config["env"] || "").each do |part| name, value = part.split("=", 2) env[name] = value end env["BUNDLE_GEMFILE"] = File.expand_path(gemfile) if gemfile end
build_switch_statement()
click to toggle source
# File lib/wwtd/run.rb, line 65 def build_switch_statement switch_ruby = Ruby.switch_statement(config["rvm"], :rerun => config[:rerun]) if switch_ruby.is_a?(Hash) env.merge!(switch_ruby) switch_ruby = nil end switch_ruby end
committed?(file)
click to toggle source
# File lib/wwtd/run.rb, line 82 def committed?(file) @committed_files ||= (File.exist?(".git") && `git ls-files`.split("\n")) || [] @committed_files.include?(file) end
flock(file) { || ... }
click to toggle source
# File lib/wwtd/run.rb, line 87 def flock(file) File.open(file, "w") do |f| begin f.flock(File::LOCK_EX) yield ensure f.flock(File::LOCK_UN) end end end
gemfile()
click to toggle source
# File lib/wwtd/run.rb, line 61 def gemfile config["gemfile"] end
sh(*args)
click to toggle source
# File lib/wwtd/run.rb, line 98 def sh(*args) ::WWTD.send(:sh, *args) end
success?()
click to toggle source
# File lib/wwtd/run.rb, line 42 def success? if wants_bundle? flock File.join(lock, (config["rvm"] || "rvm").to_s) do default_bundler_args = "--deployment --path #{Dir.pwd}/vendor/bundle" if committed?("#{gemfile || DEFAULT_GEMFILE}.lock") bundle_command = "#{switch}bundle install #{config["bundler_args"] || default_bundler_args}" return false unless sh(env, "#{bundle_command.strip} --quiet") end end SCRIPT_SECTIONS.all? do |section| env_and_command = env_and_command_for_section(section) !env_and_command || sh(*env_and_command) end end
wants_bundle?()
click to toggle source
# File lib/wwtd/run.rb, line 57 def wants_bundle? gemfile || File.exist?(DEFAULT_GEMFILE) end