Sha256: 4c5b47ccf3cca415d854acb1e6110886c2ac1b085bc5c6a6a44f8bb03e808f38

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

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

module Relish
  module Command    
    class Push < Base
      
      usage   'push <project>:<version>'
      desc    ['push features to relishapp.com',
               '<version> is optional',
               'example: relish push rspec/rspec-core',
               'example: relish push rspec/rspec-core:2.0']
      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.without_option || super()
      end
      
      def version
        @param.extract_option if @param.has_option?
      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

2 entries across 2 versions & 1 rubygems

Version Path
relish-0.1.6 lib/relish/commands/push.rb
relish-0.1.5 lib/relish/commands/push.rb