Class: Gemical::Commands::Gems

Inherits:
Base
  • Object
show all
Defined in:
lib/gemical/commands/gems.rb

Instance Method Summary collapse

Instance Method Details

#create(args, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gemical/commands/gems.rb', line 15

def create(args, options)
  terminate "Please provide a GEM file." unless args.first.is_a?(String)

  files = Pathname.glob(args).select(&:file?)
  terminate "Hmm, no files found!" if files.empty?

  authenticate!
  vault = current_vault(options)
  files.each do |file|
    upload(file, vault)
  end
rescue Gemical::Connection::HTTPNotFound
  terminate "Sorry, no such vault '#{vault}'."
rescue Gemical::Connection::HTTPUnprocessable => e
  terminate "Sorry, #{full_errors(e.response, 'name' => 'gem')}"
end

#destroy(args, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gemical/commands/gems.rb', line 32

def destroy(args, options)
  name, version = args.first(2)
  terminate "Please provide a valid GEM name." unless name.to_s =~ /\A[\w\-]+\z/
  terminate "Please provide a valid VERSION." unless version.to_s =~ /\A[\w\-\.]+\z/

  authenticate!
  vault    = current_vault(options)
  response = conn.delete("/vaults/#{vault}/gems/#{name}/#{version}")
  success "#{name} (#{version}) was successfully removed from #{vault}."
rescue Gemical::Connection::HTTPNotFound
  terminate "Sorry, unable to find '#{name} (#{version})' in vault '#{vault}'."
rescue Gemical::Connection::HTTPUnprocessable => e
  "Sorry, #{full_errors(e.response)}"
end

#index(args, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/gemical/commands/gems.rb', line 3

def index(args, options)
  authenticate!

  vault = current_vault(options)
  conn.get("/vaults/#{vault}/gems").each do |rubygem|
    versions = rubygem["versions"].map {|v| v["name"] }.sort.reverse
    say "#{rubygem["name"]} (#{versions.join(', ')})"
  end
rescue Gemical::Connection::HTTPNotFound
  terminate "Sorry, no such vault '#{vault}'."
end