Class: Gemfury::Command::App

Inherits:
Thor
  • Object
show all
Includes:
Authorization
Defined in:
lib/gemfury/command/app.rb

Constant Summary collapse

PackageExtensions =
%w(gem egg tar.gz tgz nupkg)

Instance Method Summary collapse

Methods included from Authorization

#has_credentials?, #wipe_credentials!

Methods included from Platform

#config_path, #home_directory, #on_mac?, #on_windows?

Instance Method Details

#git_listObject


152
153
154
155
156
157
158
159
# File 'lib/gemfury/command/app.rb', line 152

def git_list
  with_checks_and_rescues do
    repos = client.git_repos['repos']
    shell.say "\n*** GEMFURY GIT REPOS ***\n\n"
    names = repos.map { |r| r['name'] }
    names.sort.each { |n| shell.say(n) }
  end
end

#git_rebuild(repo) ⇒ Object


179
180
181
182
183
184
185
# File 'lib/gemfury/command/app.rb', line 179

def git_rebuild(repo)
  with_checks_and_rescues do
    params = { :revision => options[:revision] }
    shell.say "\n*** Rebuilding #{repo} repository ***\n\n"
    shell.say client.git_rebuild(repo, :build => params)
  end
end

#git_rename(repo, new_name) ⇒ Object


162
163
164
165
166
167
# File 'lib/gemfury/command/app.rb', line 162

def git_rename(repo, new_name)
  with_checks_and_rescues do
    client.git_update(repo, :repo => { :name => new_name })
    shell.say "Renamed #{repo} repository to #{new_name}\n"
  end
end

#git_reset(repo) ⇒ Object


170
171
172
173
174
175
# File 'lib/gemfury/command/app.rb', line 170

def git_reset(repo)
  with_checks_and_rescues do
    client.git_reset(repo)
    shell.say "\n*** Yanked #{repo} repository ***\n\n"
  end
end

#listObject


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gemfury/command/app.rb', line 24

def list
  with_checks_and_rescues do
    gems = client.list
    shell.say "\n*** GEMFURY PACKAGES ***\n\n"
    gems.each do |g|
      desc, version = g['name'], g.path('latest_version.version')
      desc << " (#{version ? version : 'beta'})"
      shell.say desc
    end
  end
end

#loginObject


69
70
71
72
73
74
# File 'lib/gemfury/command/app.rb', line 69

def 
  with_checks_and_rescues do
    me = client.['name']
    shell.say %Q(You are logged in as "#{me}"), :green
  end
end

#logoutObject


59
60
61
62
63
64
65
66
# File 'lib/gemfury/command/app.rb', line 59

def logout
  if !has_credentials?
    shell.say "You are logged out"
  elsif shell.yes? "Are you sure you want to log out? [yN]"
    wipe_credentials!
    shell.say "You have been logged out"
  end
end

#migrate(*paths) ⇒ Object


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/gemfury/command/app.rb', line 121

def migrate(*paths)
  with_checks_and_rescues do
    gem_paths = Dir.glob(paths.map do |p|
      if File.directory?(p)
        PackageExtensions.map { |ext| "#{p}/**/*.#{ext}" }
      elsif File.file?(p)
        p
      else
        nil
      end
    end.flatten.compact)

    if gem_paths.empty?
      die!("Problem: No valid packages found", nil, :migrate)
    else
      shell.say "Found the following packages:"
      gem_paths.each { |p| shell.say "  #{File.basename(p)}" }
      if shell.yes? "Upload these files to Gemfury? [yN]", :green
        push_files(:migrate, gem_paths)
      end
    end
  end
end

#push(*gems) ⇒ Object


17
18
19
20
21
# File 'lib/gemfury/command/app.rb', line 17

def push(*gems)
  with_checks_and_rescues do
    push_files(:push, gems)
  end
end

#sharingObject


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gemfury/command/app.rb', line 88

def sharing
  with_checks_and_rescues do
    me = client.['username']
    collaborators = client.list_collaborators
    if collaborators.empty?
      shell.say "You (#{me}) are the only collaborator", :green
    else
      shell.say %Q(\n*** Collaborators for "#{me}" ***\n), :green
      usernames = [me] + collaborators.map { |c| c['username'] }
      shell.say usernames.join("\n")
    end
    shell.say "\n"
  end
end

#sharing_add(username) ⇒ Object


104
105
106
107
108
109
# File 'lib/gemfury/command/app.rb', line 104

def sharing_add(username)
  with_checks_and_rescues do
    client.add_collaborator(username)
    shell.say "Invited #{username} as a collaborator"
  end
end

#sharing_remove(username) ⇒ Object


112
113
114
115
116
117
# File 'lib/gemfury/command/app.rb', line 112

def sharing_remove(username)
  with_checks_and_rescues do
    client.remove_collaborator(username)
    shell.say "Removed #{username} as a collaborator"
  end
end

#versionObject


11
12
13
# File 'lib/gemfury/command/app.rb', line 11

def version
  shell.say Gemfury::VERSION
end

#versions(gem_name) ⇒ Object


37
38
39
40
41
42
43
44
45
# File 'lib/gemfury/command/app.rb', line 37

def versions(gem_name)
  with_checks_and_rescues do
    versions = client.versions(gem_name)
    shell.say "\n*** #{gem_name.capitalize} Versions ***\n\n"
    versions.each do |v|
      shell.say v['version']
    end
  end
end

#whoamiObject


77
78
79
80
81
# File 'lib/gemfury/command/app.rb', line 77

def whoami
  has_credentials? ? self. : begin
    shell.say %Q(You are not logged in), :green
  end
end

#yank(gem_name) ⇒ Object


49
50
51
52
53
54
55
# File 'lib/gemfury/command/app.rb', line 49

def yank(gem_name)
  with_checks_and_rescues do
    version = options[:version]
    client.yank_version(gem_name, version)
    shell.say "\n*** Yanked #{gem_name}-#{version} ***\n\n"
  end
end