Sha256: 4d4fab809c52d5e3e930e6c5ef4164d0761483eea22ea6a0ae4b7532eba8b3cc

Contents?: true

Size: 997 Bytes

Versions: 3

Compression:

Stored size: 997 Bytes

Contents

class Kicker
  def execute_command(command)
    log "Change occured, executing command: #{command}"
    growl(GROWL_NOTIFICATIONS[:change], 'Kicker: Change occured, executing command:', command) if @use_growl
    
    output = `#{command}`
    output.strip.split("\n").each { |line| log "  #{line}" }
    
    log "Command #{last_command_succeeded? ? 'succeeded' : "failed (#{last_command_status})"}"
    
    if @use_growl
      if last_command_succeeded?
        callback = @growl_command.nil? ? GROWL_DEFAULT_CALLBACK : lambda { system(@growl_command) }
        growl(GROWL_NOTIFICATIONS[:succeeded], "Kicker: Command succeeded", output, &callback)
      else
        growl(GROWL_NOTIFICATIONS[:failed], "Kicker: Command failed (#{last_command_status})", output, &GROWL_DEFAULT_CALLBACK)
      end
    end
  end
  
  def log(message)
    puts "[#{Time.now}] #{message}"
  end
  
  private
  
  def last_command_succeeded?
    $?.success?
  end
  
  def last_command_status
    $?.to_i
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alloy-kicker-1.9.1 lib/kicker/utils.rb
alloy-kicker-1.9.2 lib/kicker/utils.rb
alloy-kicker-1.9.3 lib/kicker/utils.rb