relish 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,10 @@ module Relish
8
8
  class Base
9
9
  extend Dsl
10
10
 
11
+ option :project
12
+ option :api_token, :default => lambda { get_and_store_api_token }
13
+ option :host, :default => lambda { Relish.default_host }, :display => false
14
+
11
15
  attr_writer :args
12
16
  attr_reader :cli_options
13
17
 
@@ -15,6 +19,8 @@ module Relish
15
19
  @args = clean_args(args)
16
20
  @param = get_param
17
21
  @cli_options = Hash[*@args]
22
+
23
+ validate_cli_options
18
24
  end
19
25
 
20
26
  def url
@@ -26,12 +32,7 @@ module Relish
26
32
  end
27
33
 
28
34
  private
29
-
30
- option :organization
31
- option :project
32
- option :api_token, :default => lambda { get_and_store_api_token }
33
- option :host, :default => lambda { Relish.default_host }
34
-
35
+
35
36
  def get_and_store_api_token
36
37
  api_token = get_api_token
37
38
  global_options_file.store('api_token' => api_token)
@@ -48,13 +49,28 @@ module Relish
48
49
  def resource(options = {})
49
50
  RestClient::Resource.new(url, options)
50
51
  end
51
-
52
+
52
53
  def clean_args(args)
53
- cleaned = []
54
- args.each do |arg|
55
- cleaned << arg.sub('--', '')
54
+ args.inject([]) {|cleaned, arg| cleaned << arg.sub('--', '') }
55
+ end
56
+
57
+ def valid_option_names
58
+ self.class.option_names
59
+ end
60
+
61
+ def option_names_to_display
62
+ self.class.option_names_to_display
63
+ end
64
+
65
+ def validate_cli_options
66
+ @cli_options.keys.each do |option|
67
+ unless valid_option_names.include?(option.to_s)
68
+ puts "#{option} is not a valid option.\n" +
69
+ "Valid options are: #{option_names_to_display.sort.join(', ')}"
70
+
71
+ exit 1
72
+ end
56
73
  end
57
- cleaned
58
74
  end
59
75
 
60
76
  def global_options_file
@@ -15,9 +15,7 @@ module Relish
15
15
  end
16
16
 
17
17
  def add
18
- File.open(Relish.local_options_file, 'a') do |f|
19
- f.write(YAML::dump(Hash[*@args]))
20
- end
18
+ OptionsFile.new(Relish.local_options_file).store(@cli_options)
21
19
  end
22
20
 
23
21
  end
@@ -3,13 +3,26 @@ module Relish
3
3
  module Dsl
4
4
 
5
5
  def option(name, options = {})
6
- default_proc = options[:default] || lambda {}
6
+ name = name.to_s
7
+ default_proc = options[:default] || Proc.new {}
8
+
7
9
  define_method(name) do
8
- cli_options[name.to_s] ||
9
- local_options_file[name.to_s] ||
10
- global_options_file[name.to_s] ||
11
- instance_exec(&default_proc)
10
+ cli_options[name] ||
11
+ local_options_file[name] ||
12
+ global_options_file[name] ||
13
+ instance_exec(&default_proc)
12
14
  end
15
+
16
+ option_names << name
17
+ option_names_to_display << name unless options[:display] == false
18
+ end
19
+
20
+ def option_names
21
+ @@option_names ||= []
22
+ end
23
+
24
+ def option_names_to_display
25
+ @@option_names_to_display ||= []
13
26
  end
14
27
 
15
28
  end
@@ -35,7 +35,7 @@ module Relish
35
35
  def format(response)
36
36
  json = JSON.parse(response)
37
37
  json.map do |hash|
38
- result = hash['project']['handle']
38
+ result = hash['project']['full_handle']
39
39
  result << " (private)" if hash['project']['private']
40
40
  result
41
41
  end.join("\n")
@@ -30,7 +30,6 @@ module Relish
30
30
 
31
31
  def parameters
32
32
  "".tap do |str|
33
- str << "creator_id=#{organization}&" if organization
34
33
  str << "project_id=#{project}&"
35
34
  str << "version_id=#{version}&" if version
36
35
  str << "api_token=#{api_token}"
data/relish.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "relish"
3
- s.version = "0.0.6"
3
+ s.version = "0.0.7"
4
4
 
5
5
  s.required_rubygems_version = '>= 1.3.5'
6
6
  s.authors = ["Matt Wynne", "Justin Ko"]
@@ -4,35 +4,35 @@ module Relish
4
4
  module Command
5
5
  describe Base do
6
6
 
7
- {:organization => 'rspec', :project => 'rspec-core'}.each do |meth, name|
8
- describe "##{meth}" do
9
- context 'passed in command line' do
10
- let(:base) { described_class.new(["--#{meth}", name]) }
7
+ describe "#project" do
8
+ context 'passed in command line' do
9
+ let(:base) { described_class.new(["--project", 'rspec-core']) }
10
+
11
+ it 'returns the value' do
12
+ base.project.should eq('rspec-core')
13
+ end
14
+ end
15
+
16
+ context 'contained in the local options file' do
17
+ let(:base) { described_class.new }
11
18
 
12
- it 'returns the value' do
13
- base.send(meth).should eq(name)
14
- end
19
+ before do
20
+ OptionsFile.stub(:new).with(
21
+ Relish.local_options_file
22
+ ).and_return({'project' => 'rspec-core'})
15
23
  end
16
24
 
17
- context 'contained in the local options file' do
18
- let(:base) { described_class.new }
19
-
20
- before do
21
- OptionsFile.stub(:new).with(Relish.local_options_file).and_return({meth.to_s => name})
22
- end
23
-
24
- it 'returns the value' do
25
- base.send(meth).should eq(name)
26
- end
25
+ it 'returns the value' do
26
+ base.project.should eq('rspec-core')
27
27
  end
28
+ end
29
+
30
+ context 'not passed in command line' do
31
+ let(:base) { described_class.new }
28
32
 
29
- context 'not passed in command line' do
30
- let(:base) { described_class.new }
31
-
32
- context 'and options file does not exist' do
33
- it 'returns nil' do
34
- base.send(meth).should be_nil
35
- end
33
+ context 'and options file does not exist' do
34
+ it 'returns nil' do
35
+ base.project.should be_nil
36
36
  end
37
37
  end
38
38
  end
@@ -41,12 +41,12 @@ module Relish
41
41
  end
42
42
 
43
43
  describe '#version' do
44
- context 'with --version in @options' do
44
+ context 'with --version passed in command line' do
45
45
  let(:push) { described_class.new(['--version', 'one']) }
46
46
  specify { push.version.should eq('one') }
47
47
  end
48
48
 
49
- context 'with --version not in @options' do
49
+ context 'with --version not passed in command line' do
50
50
  let(:push) { described_class.new }
51
51
  specify { push.version.should be_nil }
52
52
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relish
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Wynne
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-23 00:00:00 +01:00
19
+ date: 2010-09-23 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency