Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Versions support.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinko committed Nov 18, 2010
1 parent 0652424 commit dcef048
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 17 deletions.
5 changes: 5 additions & 0 deletions features/help.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Feature: Help
# example: relish collab:add rspec/rspec-core:justin
collab:remove <project>:<collaborator handle or email> # remove a collaborator from a project
# example: relish collab:remove rspec/rspec-core:justin
versions # list the versions for a project
versions:add <project>:<version name> # add a version to a project
# example: relish versions:add rspec/rspec-core:2.0
versions:remove <project>:<version name> # remove a version from a project
# example: relish versions:remove rspec/rspec-core:2.0
"""

Expand Down
4 changes: 3 additions & 1 deletion lib/relish/command.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require 'relish'
require 'relish/helpers'
require 'relish/error_messages'
require 'relish/resource_methods'
require 'relish/commands/base'
require 'relish/commands/collab'
require 'relish/commands/config'
require 'relish/commands/help'
require 'relish/commands/projects'
require 'relish/commands/push'
require 'relish/commands/versions'

module Relish
module Command
Expand All @@ -23,7 +25,7 @@ def get_command_and_method(command, args)
command_class, method = command.split(':')
return get_command(command_class.capitalize), get_method(method)
rescue NameError
error ErrorMessages.unknown_command
error :unknown_command
end

private
Expand Down
14 changes: 2 additions & 12 deletions lib/relish/commands/collab.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Relish
module Command
class Collab < Base
include ResourceMethods
resource_path :memberships

desc 'list the collaborators for a project'
command :default do
Expand All @@ -23,18 +25,6 @@ class Collab < Base

private

def resource_path_for_no_option
resource_path(@param || project)
end

def resource_path_for_option
resource_path(@param.extract_project_handle || project)
end

def resource_path(project)
"projects/#{escape(project)}/memberships"
end

def handle_or_email
@param.extract_option
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relish/commands/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def handle
end

def rename_handle
@param.has_option? ? @param.extract_option : error(:handle_is_blank)
@param.has_option? ? @param.extract_option : error(:handle_blank)
end

def private?
Expand Down
42 changes: 42 additions & 0 deletions lib/relish/commands/versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Relish
module Command
class Versions < Base
include ResourceMethods
resource_path :versions

desc 'list the versions for a project'
command :default do
puts format(resource[resource_path_for_no_option].get(:accept => :json))
end

usage 'versions:add <project>:<version name>'
desc ['add a version to a project',
'example: relish versions:add rspec/rspec-core:2.0']
command :add do
puts resource[resource_path_for_option].post(
:version => { :name => version_name }
)
end

usage 'versions:remove <project>:<version name>'
desc ['remove a version from a project',
'example: relish versions:remove rspec/rspec-core:2.0']
command :remove do
puts resource["#{resource_path_for_option}/#{version_name}"].delete
end

private

def version_name
@param && @param.extract_option || error(:version_blank)
end

def format(response)
json_parse(response) do |hash|
"#{hash['version']['name']}"
end
end

end
end
end
6 changes: 5 additions & 1 deletion lib/relish/error_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ def project_blank
'Please specify a project.' + help
end

def handle_is_blank
def handle_blank
'Please specify a new handle.' + help
end

def version_blank
'Please specify a version name.' + help
end

def unknown_command
'Unknown command.' + help
Expand Down
23 changes: 23 additions & 0 deletions lib/relish/resource_methods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Relish
module ResourceMethods
def self.included(command_class)
command_class.extend ClassMethods
end

module ClassMethods
def resource_path(path)
define_method :resource_path do |project|
"projects/#{escape(project)}/#{path}"
end
end
end

def resource_path_for_no_option
resource_path(@param || project)
end

def resource_path_for_option
resource_path(@param.extract_project_handle || project)
end
end
end
12 changes: 10 additions & 2 deletions spec/relish/error_messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ module Relish
end
end

describe '#handle_is_blank' do
describe '#handle_blank' do
specify do
described_class.handle_is_blank.should eq(
described_class.handle_blank.should eq(
"Please specify a new handle. Run 'relish help' for usage information."
)
end
end

describe '#version_blank' do
specify do
described_class.version_blank.should eq(
"Please specify a version name. Run 'relish help' for usage information."
)
end
end

describe '#unknown_command' do
specify do
Expand Down

0 comments on commit dcef048

Please sign in to comment.