Class: Relish::Command::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/relish/commands/push.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_HOST, Base::GLOBAL_OPTIONS_FILE, Base::LOCAL_OPTIONS_FILE

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#api_token, #get_options, #get_param, #initialize, #organization, #parsed_options_file, #project, #resource, #url

Constructor Details

This class inherits a constructor from Relish::Command::Base

Instance Method Details

#defaultObject



14
15
16
# File 'lib/relish/commands/push.rb', line 14

def default
  run
end

#filesObject



58
59
60
# File 'lib/relish/commands/push.rb', line 58

def files
  Dir['features/**/*.{feature,md,markdown}']
end

#files_as_tar_gzObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/relish/commands/push.rb', line 44

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

#parametersObject



30
31
32
33
34
35
36
37
38
# File 'lib/relish/commands/push.rb', line 30

def parameters
  "".tap do |str|
    str << "pushes?"
    str << "creator_id=#{organization}&" if organization
    str << "project_id=#{project}&"
    str << "version_id=#{version}&" if version
    str << "api_token=#{api_token}"
  end
end

#post(tar_gz_data) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/relish/commands/push.rb', line 22

def post(tar_gz_data)
  resource[parameters].post(tar_gz_data, :content_type => 'application/x-gzip')
  puts "sent:\n#{files.join("\n")}"
rescue RestClient::Exception => exception
  warn exception.response
  exit 1
end

#runObject



18
19
20
# File 'lib/relish/commands/push.rb', line 18

def run
  post files_as_tar_gz
end

#versionObject



40
41
42
# File 'lib/relish/commands/push.rb', line 40

def version
  @options['--version'] || @options['-v']
end