relish 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/relish/commands/base.rb +27 -11
- data/lib/relish/commands/config.rb +1 -3
- data/lib/relish/commands/dsl.rb +18 -5
- data/lib/relish/commands/projects.rb +1 -1
- data/lib/relish/commands/push.rb +0 -1
- data/relish.gemspec +1 -1
- data/spec/relish/commands/base_spec.rb +24 -24
- data/spec/relish/commands/push_spec.rb +2 -2
- metadata +4 -4
data/lib/relish/commands/base.rb
CHANGED
@@ -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
|
-
|
55
|
-
|
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
|
data/lib/relish/commands/dsl.rb
CHANGED
@@ -3,13 +3,26 @@ module Relish
|
|
3
3
|
module Dsl
|
4
4
|
|
5
5
|
def option(name, options = {})
|
6
|
-
|
6
|
+
name = name.to_s
|
7
|
+
default_proc = options[:default] || Proc.new {}
|
8
|
+
|
7
9
|
define_method(name) do
|
8
|
-
cli_options[name
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
data/lib/relish/commands/push.rb
CHANGED
data/relish.gemspec
CHANGED
@@ -4,35 +4,35 @@ module Relish
|
|
4
4
|
module Command
|
5
5
|
describe Base do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
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 '
|
30
|
-
|
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
|
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
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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
|
19
|
+
date: 2010-09-23 00:00:00 -06:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|