Sha256: 44e74d2a80992a46cd74554e7a1103f576b2f4921fb56a39b982635bf9e5a1d9

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

#encoding: utf-8
require 'vagabond/constants'

module Vagabond
  module Helpers
    module Callbacks

      def callbacks(key)
        if(vagabondfile[:callbacks][key])
          if(options[:callbacks])
            ui.info "  Running #{ui.color(key, :bold)} callbacks..."
            if(options[:cluster])
              cluster_name = name
              names = vagabondfile[:clusters][name] if vagabondfile[:clusters]
            else
              names = [name]
            end
            names.compact.each do |n|
              @name = n
              callbacks = Array(vagabondfile.callbacks_for(name)[key]).compact.flatten
              callbacks.each do |command|
                Array(command.scan(/\$\{(\w+)\}/).first).each do |repl|
                  command = command.gsub("${#{repl}}", self.send(repl.downcase))
                end
                ui.info "    Running: #{command}"
                opts = {:timeout => 30}
                opts.merge(vagabondfile[:callbacks][:options] || {})
                cmd = Mixlib::ShellOut.new(command,
                  opts.merge(:live_stream => options[:debug])
                )
                cmd.run_command
                if(cmd.status.success?)
                  ui.info ui.color('      -> SUCCESS', :green)
                else
                  ui.info ui.color("      -> FAILED - (#{cmd.stderr.strip.gsub("\n", ' ')})", :red)
                end
              end
            end
            @name = cluster_name if cluster_name
            ui.info ui.color('  -> COMPLETE', :green)
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagabond-0.2.10 lib/vagabond/helpers/callbacks.rb