Sha256: 8003cd42f1210f31f5d005d550d3708c1a58aaed4e43af13dd49f1f5a7b06390

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

require 'yaml'

Capistrano::Configuration.instance(:must_exist).load do
  namespace :notify do
    begin
      require 'broach'
    rescue LoadError
      def notify(action)
        puts "[!] Please `gem install broach' to post deployment messages to Campfire."
      end
    else
      def uses_instances?
        !variables[:instances].nil? and !variables[:instances].empty?
      end
      
      def instances_as_sentence
        case instances.length
        when 0
          ''
        when 1
          instances.first
        when 2
          instances.join(' and ')
        else
          message = instances[0..-2].join(', ')
          message << ", and #{instances.last}"
          message
        end
      end
      
      def message(action)
        message = "#{ENV['USER']} just #{action} #{application}"
        message << " (#{variables[:url]})" if variables[:url]
        if uses_instances?
          message << " to instances: #{instances_as_sentence}"
        end
        message
      end
      
      def notify(action)
        begin
          Broach.settings =  YAML.load_file(File.expand_path('~/.fingercap.yml'))['campfire']
        rescue Errno::ENOENT
          puts "[!] Fingercap can't find it's configuration file at ~/.fingercap.yml"
          puts File.read(File.expand_path('../../../../examples/fingercap.yml', __FILE__))
          exit -1
        end
        Broach.speak(Broach.session.room, message(action))
      end
    end
    
    desc "Posts a `deployed' message to Campfire"
    task :deploy do
      notify "deployed"
    end
    
    desc "Posts a `deployed and migrated' message to Campfire"
    task :migrations do
      notify "deployed and migrated"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fingercap-0.4.5 lib/fingercap/recipes/notify.rb
fingercap-0.4.4 lib/fingercap/recipes/notify.rb
fingercap-0.4.3 lib/fingercap/recipes/notify.rb
fingercap-0.4.1 lib/fingercap/recipes/notify.rb
fingercap-0.4 lib/fingercap/recipes/notify.rb
fingercap-0.3.4 lib/fingercap/recipes/notify.rb