rprogram 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,11 +25,11 @@ module RProgram
25
25
  # # ...
26
26
  # end
27
27
  #
28
- def initialize(options={},&block)
28
+ def initialize(options={})
29
29
  @subtasks = {}
30
- @options = options
30
+ @options = options
31
31
 
32
- block.call(self) if block
32
+ yield self if block_given?
33
33
  end
34
34
 
35
35
  #
@@ -293,7 +293,12 @@ module RProgram
293
293
  return leading_non_options + options + tailing_args
294
294
  end
295
295
 
296
- alias to_a arguments
296
+ #
297
+ # @see #arguments
298
+ #
299
+ def to_a
300
+ arguments
301
+ end
297
302
 
298
303
  protected
299
304
 
@@ -487,17 +492,14 @@ module RProgram
487
492
  # Task.flag_namify('--output-file')
488
493
  # # => "output_file"
489
494
  #
490
- def Task.flag_namify(flag)
495
+ def self.flag_namify(flag)
491
496
  flag = flag.to_s.downcase
492
497
 
493
498
  # remove leading dashes
494
- if flag[0..1] == '--'
495
- method_name = flag[2..-1]
496
- elsif flag[0..0] == '-'
497
- method_name = flag[1..-1]
498
- else
499
- method_name = flag
500
- end
499
+ method_name = if flag.start_with?('--') then flag[2..-1]
500
+ elsif flag.start_with?('-') then flag[1..-1]
501
+ else flag
502
+ end
501
503
 
502
504
  # replace remaining dashes with underscores
503
505
  return method_name.gsub(/[-_\.\s]+/,'_')
@@ -1,4 +1,4 @@
1
1
  module RProgram
2
2
  # Version of RProgram
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
@@ -2,104 +2,59 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- Gem::Specification.new do |gemspec|
6
- root = File.dirname(__FILE__)
7
- lib_dir = File.join(root,'lib')
8
- files = `git ls-files`.split($/)
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
9
7
 
10
- filter_files = lambda { |paths|
11
- files & case paths
12
- when Array
13
- paths
14
- when String
15
- Dir[paths]
16
- end
17
- }
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
18
12
 
19
- version = {
20
- :file => 'rprogram/version',
21
- :constant => 'RProgram::VERSION'
22
- }
13
+ require 'rprogram/version'
14
+ RProgram::VERSION
15
+ end
23
16
 
24
- defaults = {
25
- 'name' => File.basename(root),
26
- 'files' => files,
27
- 'require_paths' => ['ext', 'lib'].select { |dir| File.directory?(dir) },
28
- 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
29
- 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
30
- 'doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
31
- 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}']
32
- }
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
33
23
 
34
- metadata = defaults.merge(YAML.load_file('gemspec.yml'))
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
35
25
 
36
- gemspec.name = metadata['name']
37
- gemspec.version = if metadata['version']
38
- metadata['version']
39
- else
40
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
41
28
 
42
- require version[:file]
43
- eval(version[:constant])
44
- end
45
-
46
- gemspec.summary = metadata.fetch('summary',metadata['description'])
47
- gemspec.description = metadata.fetch('description',metadata['summary'])
48
-
49
- gemspec.licenses = Array(metadata['license'])
50
- gemspec.authors = Array(metadata['authors'])
51
-
52
- gemspec.email = metadata['email']
53
- gemspec.homepage = metadata['homepage']
54
-
55
- gemspec.require_paths = Array(metadata['require_paths'])
56
- gemspec.files = filter_files[metadata['files']]
57
- gemspec.files += Array(metadata['generated_files'])
58
- gemspec.executables = metadata['executables']
59
- gemspec.extensions = metadata['extensions']
60
-
61
- if Gem::VERSION < '1.7.'
62
- gemspec.default_executable = gemspec.executables.first
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
63
31
  end
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
64
33
 
65
- gemspec.test_files = filter_files[metadata['test_files']]
66
- gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
67
-
68
- gemspec.post_install_message = metadata['post_install_message']
69
- gemspec.requirements = metadata['requirements']
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
70
37
 
71
- if gemspec.respond_to?(:required_ruby_version=)
72
- gemspec.required_ruby_version = metadata['required_ruby_version']
73
- end
74
-
75
- if gemspec.respond_to?(:required_rubygems_version=)
76
- gemspec.required_rubygems_version = metadata['required_ruby_version']
77
- end
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
78
41
 
79
- parse_versions = lambda { |versions|
80
- case versions
81
- when Array
82
- versions.map { |v| v.to_s }
83
- when String
84
- versions.split(/,\s*/)
85
- end
86
- }
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
87
46
 
88
- if metadata['dependencies']
89
- metadata['dependencies'].each do |name,versions|
90
- gemspec.add_dependency(name,parse_versions[versions])
91
- end
92
- end
47
+ split = lambda { |string| string.split(/,\s*/) }
93
48
 
94
- if metadata['runtime_dependencies']
95
- metadata['runtime_dependencies'].each do |name,versions|
96
- gemspec.add_runtime_dependency(name,parse_versions[versions])
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
97
52
  end
98
53
  end
99
54
 
100
- if metadata['development_dependencies']
101
- metadata['development_dependencies'].each do |name,versions|
102
- gemspec.add_development_dependency(name,parse_versions[versions])
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
103
58
  end
104
59
  end
105
60
  end
@@ -1,3 +1,5 @@
1
+ require 'rprogram/program'
2
+
1
3
  class AliasedProgram < RProgram::Program
2
4
 
3
5
  name_program 'ls'
@@ -1,3 +1,5 @@
1
+ require 'rprogram/program'
2
+
1
3
  class NamedProgram < RProgram::Program
2
4
 
3
5
  name_program 'ls'
@@ -1,11 +1,9 @@
1
- require 'rprogram/non_option'
2
-
3
1
  require 'spec_helper'
4
2
 
3
+ require 'rprogram/non_option'
4
+
5
5
  describe NonOption do
6
- before(:all) do
7
- @non_option = NonOption.new(:name => 'files')
8
- end
6
+ subject { NonOption.new(:name => 'files') }
9
7
 
10
8
  it "should keep :leading and :tailing options mutually exclusive" do
11
9
  leading = NonOption.new(:name => 'files', :leading => true)
@@ -19,30 +17,30 @@ describe NonOption do
19
17
  end
20
18
 
21
19
  it "should return an empty Array when passed nil" do
22
- @non_option.arguments(nil).should == []
20
+ subject.arguments(nil).should == []
23
21
  end
24
22
 
25
23
  it "should return an empty Array when passed false" do
26
- @non_option.arguments(false).should == []
24
+ subject.arguments(false).should == []
27
25
  end
28
26
 
29
27
  it "should return an empty Array when passed []" do
30
- @non_option.arguments([]).should == []
28
+ subject.arguments([]).should == []
31
29
  end
32
30
 
33
31
  it "should return an Array when passed a single value" do
34
- @non_option.arguments('foo').should == ['foo']
32
+ subject.arguments('foo').should == ['foo']
35
33
  end
36
34
 
37
35
  it "should return an Array when passed multiple values" do
38
- @non_option.arguments(['foo', 'bar']).should == ['foo', 'bar']
36
+ subject.arguments(['foo', 'bar']).should == ['foo', 'bar']
39
37
  end
40
38
 
41
39
  it "should return an Array when passed a Hash of keys" do
42
- @non_option.arguments({:foo => true, :bar => false}).should == ['foo']
40
+ subject.arguments({:foo => true, :bar => false}).should == ['foo']
43
41
  end
44
42
 
45
43
  it "should return an Array when passed a Hash of values" do
46
- @non_option.arguments({:foo => 'bar'}).should == ['foo=bar']
44
+ subject.arguments({:foo => 'bar'}).should == ['foo=bar']
47
45
  end
48
46
  end
@@ -1,17 +1,15 @@
1
- require 'rprogram/option'
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  shared_examples_for 'Option' do
6
4
  it "should return an empty Array when passed nil" do
7
- @option.arguments(nil).should == []
5
+ subject.arguments(nil).should == []
8
6
  end
9
7
 
10
8
  it "should return an empty Array when passed false" do
11
- @option.arguments(false).should == []
9
+ subject.arguments(false).should == []
12
10
  end
13
11
 
14
12
  it "should return a single flag when passed true" do
15
- @option.arguments(true).should == ['-f']
13
+ subject.arguments(true).should == ['-f']
16
14
  end
17
15
  end
@@ -1,25 +1,21 @@
1
- require 'rprogram/option_list'
2
-
3
1
  require 'spec_helper'
4
2
 
5
- describe OptionList do
6
- before(:each) do
7
- @options = OptionList.new
8
- end
3
+ require 'rprogram/option_list'
9
4
 
5
+ describe OptionList do
10
6
  it "should behave like a Hash" do
11
- @options[:bla] = 2
12
- @options[:bla].should == 2
7
+ subject[:bla] = 2
8
+ subject[:bla].should == 2
13
9
  end
14
10
 
15
11
  it "should provide reader and writer methods" do
16
- @options.bla = 5
17
- @options.bla.should == 5
12
+ subject.bla = 5
13
+ subject.bla.should == 5
18
14
  end
19
15
 
20
16
  it "should raise a NoMethodError exception when calling other methods" do
21
17
  lambda {
22
- @options.bla(5)
18
+ subject.bla(5)
23
19
  }.should raise_error(NoMethodError)
24
20
  end
25
21
  end
@@ -1,52 +1,50 @@
1
- require 'rprogram/option'
2
-
3
1
  require 'spec_helper'
4
2
  require 'option_examples'
5
3
 
4
+ require 'rprogram/option'
5
+
6
6
  describe Option do
7
7
  describe "custom formatting" do
8
8
  it "should allow the format block to return nil" do
9
- opt = Option.new(:flag => '-f') { |opt,value| }
9
+ opt = described_class.new(:flag => '-f') { |opt,value| }
10
10
 
11
11
  opt.arguments('bla').should == []
12
12
  end
13
13
  end
14
14
 
15
15
  describe "single flag" do
16
- before(:all) do
17
- @option = Option.new(:flag => '-f')
18
- end
16
+ subject { described_class.new(:flag => '-f') }
19
17
 
20
18
  it_should_behave_like 'Option'
21
19
 
22
20
  it "should render a single flag with an optional value" do
23
21
  value = 'foo'
24
22
 
25
- @option.arguments('foo').should == ['-f', 'foo']
23
+ subject.arguments('foo').should == ['-f', 'foo']
26
24
  end
27
25
 
28
26
  it "should render a single flag with multiple values" do
29
27
  value = ['foo','bar','baz']
30
28
 
31
- @option.arguments(value).should == ['-f','foo','bar','baz']
29
+ subject.arguments(value).should == ['-f','foo','bar','baz']
32
30
  end
33
31
 
34
32
  it "should render a single flag with a Hash of keys" do
35
33
  value = {:foo => true, :bar => false}
36
34
 
37
- @option.arguments(value).should == ['-f','foo']
35
+ subject.arguments(value).should == ['-f','foo']
38
36
  end
39
37
 
40
38
  it "should render a single flag with a Hash of keys and values" do
41
39
  value = {:foo => 'bar'}
42
40
 
43
- @option.arguments(value).should == ['-f','foo=bar']
41
+ subject.arguments(value).should == ['-f','foo=bar']
44
42
  end
45
43
  end
46
44
 
47
45
  describe "equals flag" do
48
- before(:all) do
49
- @option = Option.new(:equals => true, :flag => '-f')
46
+ subject do
47
+ described_class.new(:equals => true, :flag => '-f')
50
48
  end
51
49
 
52
50
  it_should_behave_like 'Option'
@@ -54,25 +52,25 @@ describe Option do
54
52
  it "should render a single flag with a value" do
55
53
  value = 'foo'
56
54
 
57
- @option.arguments('foo').should == ['-f=foo']
55
+ subject.arguments('foo').should == ['-f=foo']
58
56
  end
59
57
 
60
58
  it "should render a single flag with multiple values" do
61
59
  value = ['foo', 'bar', 'baz']
62
60
 
63
- @option.arguments(value).should == ['-f=foo bar baz']
61
+ subject.arguments(value).should == ['-f=foo bar baz']
64
62
  end
65
63
 
66
64
  it "should render a single flag with a Hash of keys" do
67
65
  value = {:foo => true, :bar => false}
68
66
 
69
- @option.arguments(value).should == ['-f=foo']
67
+ subject.arguments(value).should == ['-f=foo']
70
68
  end
71
69
  end
72
70
 
73
71
  describe "multiple flags" do
74
- before(:all) do
75
- @option = Option.new(:multiple => true, :flag => '-f')
72
+ subject do
73
+ described_class.new(:multiple => true, :flag => '-f')
76
74
  end
77
75
 
78
76
  it_should_behave_like 'Option'
@@ -80,18 +78,18 @@ describe Option do
80
78
  it "should render a single flag with a value" do
81
79
  value = 'foo'
82
80
 
83
- @option.arguments(value).should == ['-f', 'foo']
81
+ subject.arguments(value).should == ['-f', 'foo']
84
82
  end
85
83
 
86
84
  it "should render multiple flags for multiple values" do
87
85
  value = ['foo','bar','baz']
88
86
 
89
- @option.arguments(value).should == ['-f', 'foo', '-f', 'bar', '-f', 'baz']
87
+ subject.arguments(value).should == ['-f', 'foo', '-f', 'bar', '-f', 'baz']
90
88
  end
91
89
 
92
90
  it "should render multiple flags for a Hash of keys" do
93
91
  value = {:foo => true, :bar => true, :baz => false}
94
- args = @option.arguments(value)
92
+ args = subject.arguments(value)
95
93
 
96
94
  (args & ['-f', 'foo']).should == ['-f', 'foo']
97
95
  (args & ['-f', 'bar']).should == ['-f', 'bar']
@@ -100,13 +98,13 @@ describe Option do
100
98
  it "should render multiple flags for a Hash of values" do
101
99
  value = {:foo => 'bar'}
102
100
 
103
- @option.arguments(value).should == ['-f', 'foo=bar']
101
+ subject.arguments(value).should == ['-f', 'foo=bar']
104
102
  end
105
103
  end
106
104
 
107
105
  describe "multiple equals flags" do
108
- before(:all) do
109
- @option = Option.new(:multiple => true, :equals => true, :flag => '-f')
106
+ subject do
107
+ described_class.new(:multiple => true, :equals => true, :flag => '-f')
110
108
  end
111
109
 
112
110
  it_should_behave_like 'Option'
@@ -114,18 +112,18 @@ describe Option do
114
112
  it "should render a single flag with a value" do
115
113
  value = 'foo'
116
114
 
117
- @option.arguments(value).should == ['-f=foo']
115
+ subject.arguments(value).should == ['-f=foo']
118
116
  end
119
117
 
120
118
  it "should render multiple equal flags for multiple values" do
121
119
  value = ['foo', 'bar']
122
120
 
123
- @option.arguments(value).should == ['-f=foo', '-f=bar']
121
+ subject.arguments(value).should == ['-f=foo', '-f=bar']
124
122
  end
125
123
 
126
124
  it "should render multiple equal flags for a Hash of keys" do
127
125
  value = {:foo => true, :bar => true, :baz => false}
128
- args = @option.arguments(value)
126
+ args = subject.arguments(value)
129
127
 
130
128
  args.include?('-f=foo').should == true
131
129
  args.include?('-f=bar').should == true
@@ -133,7 +131,7 @@ describe Option do
133
131
 
134
132
  it "should render multiple equal flags for a Hash of values" do
135
133
  value = {:foo => 'bar', :bar => 'baz'}
136
- args = @option.arguments(value)
134
+ args = subject.arguments(value)
137
135
 
138
136
  args.include?('-f=foo=bar').should == true
139
137
  args.include?('-f=bar=baz').should == true
@@ -141,8 +139,8 @@ describe Option do
141
139
  end
142
140
 
143
141
  describe "separated values" do
144
- before(:all) do
145
- @option = Option.new(:separator => ',', :flag => '-f')
142
+ subject do
143
+ described_class.new(:separator => ',', :flag => '-f')
146
144
  end
147
145
 
148
146
  it_should_behave_like 'Option'
@@ -150,18 +148,18 @@ describe Option do
150
148
  it "should render a single flag with a value" do
151
149
  value = 'foo'
152
150
 
153
- @option.arguments('foo').should == ['-f', 'foo']
151
+ subject.arguments('foo').should == ['-f', 'foo']
154
152
  end
155
153
 
156
154
  it "should render a single flag with multiple values" do
157
155
  value = ['foo', 'bar', 'baz']
158
156
 
159
- @option.arguments(value).should == ['-f', 'foo,bar,baz']
157
+ subject.arguments(value).should == ['-f', 'foo,bar,baz']
160
158
  end
161
159
 
162
160
  it "should render a single flag with a Hash of keys" do
163
161
  value = {:foo => true, :bar => true, :baz => false}
164
- args = @option.arguments(value)
162
+ args = subject.arguments(value)
165
163
 
166
164
  args[0].should == '-f'
167
165
 
@@ -173,7 +171,7 @@ describe Option do
173
171
 
174
172
  it "should render a single flag with a Hash of values" do
175
173
  value = {:foo => 'bar', :bar => 'baz'}
176
- args = @option.arguments(value)
174
+ args = subject.arguments(value)
177
175
 
178
176
  args[0].should == '-f'
179
177