Sha256: 91fca238d2f6ba1adde157a1f91685633479bfb20e3e82dbd0fe6eac073ec9b4

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'zlib'
require 'archive/tar/minitar'
require 'stringio'
require 'rest_client'

module Relish
  module Command    
    class Push < Base
      option :version
      
      usage   'push <project>'
      desc    'push features to relishapp.com'
      command :default do
        post files_as_tar_gz
      end
      
    private
          
      def post(tar_gz_data)
        resource["pushes?#{parameters}"].post(tar_gz_data,
          :content_type => 'application/x-gzip')
        puts "sent:\n#{files.join("\n")}"
      end
      
      def parameters
        "".tap do |str|
          str << "project_id=#{project}"
          str << "&version_id=#{version}" if version
        end
      end
      
      def project
        @param || super()
      end
      
      def files_as_tar_gz
        stream = StringIO.new
        begin
          tgz = Zlib::GzipWriter.new(stream)
          tar = Archive::Tar::Minitar::Output.new(tgz)
          files.each do |entry|
            Archive::Tar::Minitar.pack_file(entry, tar)
          end
        ensure
          tar.close if tar # Closes both tar and tgz.
        end
        stream.string
      end
      
      def files
        Dir['features/**/*.{feature,md,markdown}']
      end
      
    end
    

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relish-0.1.4 lib/relish/commands/push.rb
relish-0.1.3 lib/relish/commands/push.rb
relish-0.1.2 lib/relish/commands/push.rb
relish-0.1.1 lib/relish/commands/push.rb