ru 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemfiles/activesupport_3.gemfile.lock +4 -4
- data/gemfiles/activesupport_4.gemfile.lock +4 -4
- data/lib/ru/version.rb +1 -1
- data/ru.gemspec +3 -3
- data/spec/examples/misc_examples_spec.rb +4 -3
- data/spec/examples/sed_examples_spec.rb +11 -11
- data/spec/lib/array_spec.rb +6 -6
- data/spec/lib/iterator_spec.rb +3 -3
- data/spec/lib/process_spec.rb +25 -25
- data/spec/support/process_helper.rb +1 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad7c3f3ddc9d77fd0352287f8b7ec243c3fac57
|
4
|
+
data.tar.gz: 200ee9c700cd3326ac54205e893b26e5922d0bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ab743fde833e704129f635a022baa209437128bf9450eaeec72c693516a4a3d2d394c4afc0e98dc58b827417515b6809051888b3fe0e3277ba2a972d988ee8a
|
7
|
+
data.tar.gz: 8f1f5625d6f4b1d25907a57a08a55d95c1bf86312f4e3bb3625b27650f6bc154468ab13e14c2a87ebfb7c0a461329cd8c35c45d6bb7f03b87b0245f495e748ea
|
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
ru (0.1.
|
5
|
-
activesupport
|
4
|
+
ru (0.1.2)
|
5
|
+
activesupport (>= 3.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -37,6 +37,6 @@ PLATFORMS
|
|
37
37
|
|
38
38
|
DEPENDENCIES
|
39
39
|
activesupport (= 3.2.20)
|
40
|
-
appraisal
|
41
|
-
rspec
|
40
|
+
appraisal (~> 1.0)
|
41
|
+
rspec (~> 3.1)
|
42
42
|
ru!
|
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
ru (0.1.
|
5
|
-
activesupport
|
4
|
+
ru (0.1.2)
|
5
|
+
activesupport (>= 3.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -44,6 +44,6 @@ PLATFORMS
|
|
44
44
|
|
45
45
|
DEPENDENCIES
|
46
46
|
activesupport (= 4.1.7)
|
47
|
-
appraisal
|
48
|
-
rspec
|
47
|
+
appraisal (~> 1.0)
|
48
|
+
rspec (~> 3.1)
|
49
49
|
ru!
|
data/lib/ru/version.rb
CHANGED
data/ru.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.version = Ru::VERSION
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
|
-
s.add_dependency 'activesupport'
|
16
|
+
s.add_dependency 'activesupport', '>= 3.2.0'
|
17
17
|
|
18
|
-
s.add_development_dependency 'appraisal'
|
19
|
-
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'appraisal', '~> 1.0'
|
19
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
20
20
|
end
|
@@ -9,7 +9,7 @@ describe 'misc examples' do
|
|
9
9
|
it "sums" do
|
10
10
|
lines = (1..10).to_a.map(&:to_s)
|
11
11
|
out = run('map(:to_i).sum', lines)
|
12
|
-
out.
|
12
|
+
expect(out).to eq('55')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -18,7 +18,7 @@ describe 'misc examples' do
|
|
18
18
|
it "prints" do
|
19
19
|
lines = (1..10).to_a.map(&:to_s)
|
20
20
|
out = run('[4]', lines)
|
21
|
-
out.
|
21
|
+
expect(out).to eq('5')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,13 +27,14 @@ describe 'misc examples' do
|
|
27
27
|
it "sorts" do
|
28
28
|
file = fixture_path('files', 'access.log')
|
29
29
|
out = run(['map { |line| [line[/(\d+)( ".+"){2}$/, 1].to_i, line] }.sort.reverse.map(:join, " ")', file])
|
30
|
-
out.
|
30
|
+
expect(out).to eq(<<-EOF.strip
|
31
31
|
584912 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET /file.txt HTTP/1.0" 200 584912 "-" "Googlebot/2.1"
|
32
32
|
6433 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET / HTTP/1.0" 200 6433 "-" "Googlebot/2.1"
|
33
33
|
6433 66.249.64.13 - - [18/Sep/2004:11:07:48 +1000] "GET / HTTP/1.0" 200 6433 "-" "Googlebot/2.1"
|
34
34
|
468 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET /robots.txt HTTP/1.0" 200 468 "-" "Googlebot/2.1"
|
35
35
|
468 66.249.64.13 - - [18/Sep/2004:11:07:48 +1000] "GET /robots.txt HTTP/1.0" 200 468 "-" "Googlebot/2.1"
|
36
36
|
EOF
|
37
|
+
)
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -9,7 +9,7 @@ describe 'sed examples' do
|
|
9
9
|
it "centers" do
|
10
10
|
lines = %w{john paul george} + [' ringo ']
|
11
11
|
out = run('each_line.strip.center(10)', lines)
|
12
|
-
out.
|
12
|
+
expect(out).to eq(" john \n paul \n george \n ringo ")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -17,7 +17,7 @@ describe 'sed examples' do
|
|
17
17
|
it "increments" do
|
18
18
|
lines = ('5'..'10').to_a
|
19
19
|
out = run('(each_line.to_i+1)', lines)
|
20
|
-
out.
|
20
|
+
expect(out).to eq(('6'..'11').to_a.join("\n"))
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -25,7 +25,7 @@ describe 'sed examples' do
|
|
25
25
|
it "reverses" do
|
26
26
|
lines = %w{john paul george ringo}
|
27
27
|
out = run('each_line.reverse', lines)
|
28
|
-
out.
|
28
|
+
expect(out).to eq("nhoj\nluap\negroeg\nognir")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ describe 'sed examples' do
|
|
33
33
|
it "numbers" do
|
34
34
|
lines = %w{john paul george ringo}
|
35
35
|
out = run('map.with_index { |line, index| "#{(index+1).to_s.rjust(6)} #{line}" }', lines)
|
36
|
-
out.
|
36
|
+
expect(out).to eq(" 1 john\n 2 paul\n 3 george\n 4 ringo")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -41,7 +41,7 @@ describe 'sed examples' do
|
|
41
41
|
it "counts" do
|
42
42
|
lines = %w{john paul george ringo}
|
43
43
|
out = run('length', lines)
|
44
|
-
out.
|
44
|
+
expect(out).to eq("4")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,7 +49,7 @@ describe 'sed examples' do
|
|
49
49
|
it "prints" do
|
50
50
|
lines = %w{john paul george ringo}
|
51
51
|
out = run('[0,2]', lines)
|
52
|
-
out.
|
52
|
+
expect(out).to eq("john\npaul")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -57,7 +57,7 @@ describe 'sed examples' do
|
|
57
57
|
it "prints" do
|
58
58
|
lines = %w{john paul george ringo}
|
59
59
|
out = run('[2..-1]', lines)
|
60
|
-
out.
|
60
|
+
expect(out).to eq("george\nringo")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -65,7 +65,7 @@ describe 'sed examples' do
|
|
65
65
|
it "dedupes" do
|
66
66
|
lines = %w{john john paul george george george ringo}
|
67
67
|
out = run('uniq', lines)
|
68
|
-
out.
|
68
|
+
expect(out).to eq("john\npaul\ngeorge\nringo")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ describe 'sed examples' do
|
|
73
73
|
it "prints" do
|
74
74
|
lines = %w{john john paul george george george ringo}
|
75
75
|
out = run('select { |line| self.count(line) > 1 }', lines)
|
76
|
-
out.
|
76
|
+
expect(out).to eq("john\njohn\ngeorge\ngeorge\ngeorge")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -81,7 +81,7 @@ describe 'sed examples' do
|
|
81
81
|
it "removes" do
|
82
82
|
lines = %w{john john paul george george george ringo}
|
83
83
|
out = run('select { |line| self.count(line) == 1 }', lines)
|
84
|
-
out.
|
84
|
+
expect(out).to eq("paul\nringo")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -89,7 +89,7 @@ describe 'sed examples' do
|
|
89
89
|
it "squeezes" do
|
90
90
|
lines = "john\n\npaul\ngeorge\n\n\nringo"
|
91
91
|
out = run('to_s.squeeze("\n")', lines)
|
92
|
-
out.
|
92
|
+
expect(out).to eq("john\npaul\ngeorge\nringo")
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
data/spec/lib/array_spec.rb
CHANGED
@@ -4,35 +4,35 @@ describe Ru::Array do
|
|
4
4
|
describe "Array method" do
|
5
5
|
it "returns a Ru::Array" do
|
6
6
|
array = described_class.new(%w{john paul george ringo})
|
7
|
-
array.sort.
|
7
|
+
expect(array.sort).to be_a(Ru::Array)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#each_line" do
|
12
12
|
it "calls to_s" do
|
13
13
|
array = described_class.new((1..3).to_a)
|
14
|
-
array.each_line.to_s.to_a.
|
14
|
+
expect(array.each_line.to_s.to_a).to eq(described_class.new(('1'..'3')))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "calls methods with arguments" do
|
18
18
|
array = described_class.new((1..3).to_a)
|
19
|
-
array.each_line.modulo(2).to_a.
|
19
|
+
expect(array.each_line.modulo(2).to_a).to eq([1, 0, 1])
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#map" do
|
24
24
|
it "takes one argument" do
|
25
25
|
array = described_class.new(%w{john paul george ringo})
|
26
|
-
array.map(:reverse).
|
26
|
+
expect(array.map(:reverse)).to eq(%w{nhoj luap egroeg ognir})
|
27
27
|
end
|
28
28
|
it "takes two arguments" do
|
29
29
|
array = described_class.new(%w{john paul george ringo})
|
30
|
-
array.map(:[], 0).
|
30
|
+
expect(array.map(:[], 0)).to eq(%w{j p g r})
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns a Ru::Array" do
|
34
34
|
array = described_class.new(%w{john paul george ringo})
|
35
|
-
array.map(:[], 0).
|
35
|
+
expect(array.map(:[], 0)).to be_a(Ru::Array)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/spec/lib/iterator_spec.rb
CHANGED
@@ -4,20 +4,20 @@ describe Ru::Iterator do
|
|
4
4
|
describe "#to_a" do
|
5
5
|
it "returns the array" do
|
6
6
|
iterator = described_class.new(%w{john paul george ringo})
|
7
|
-
iterator.to_a.
|
7
|
+
expect(iterator.to_a).to eq(%w{john paul george ringo})
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#to_dotsch_output" do
|
12
12
|
it "returns the string" do
|
13
13
|
iterator = described_class.new(%w{john paul george ringo})
|
14
|
-
iterator.to_dotsch_output.
|
14
|
+
expect(iterator.to_dotsch_output).to eq("john\npaul\ngeorge\nringo")
|
15
15
|
end
|
16
16
|
|
17
17
|
context "with a method called on it" do
|
18
18
|
it "returns the string" do
|
19
19
|
iterator = described_class.new(%w{john paul george ringo})
|
20
|
-
iterator.to_s.to_dotsch_output.
|
20
|
+
expect(iterator.to_s.to_dotsch_output).to eq("john\npaul\ngeorge\nringo")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/spec/lib/process_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Ru::Process do
|
|
8
8
|
it "runs []" do
|
9
9
|
lines = %w{john paul george ringo}
|
10
10
|
out = run('[1,2]', lines)
|
11
|
-
out.
|
11
|
+
expect(out).to eq("paul\ngeorge")
|
12
12
|
end
|
13
13
|
|
14
14
|
it "runs files" do
|
@@ -17,7 +17,7 @@ describe Ru::Process do
|
|
17
17
|
fixture_path('files', 'foo.txt')
|
18
18
|
]
|
19
19
|
out = run('files', paths)
|
20
|
-
out.
|
20
|
+
expect(out).to eq("bar.txt\nfoo.txt")
|
21
21
|
end
|
22
22
|
|
23
23
|
it "runs format" do
|
@@ -27,47 +27,47 @@ describe Ru::Process do
|
|
27
27
|
]
|
28
28
|
out = run("files.format('l')", paths)
|
29
29
|
lines = out.split("\n")
|
30
|
-
lines.length.
|
30
|
+
expect(lines.length).to eq(2)
|
31
31
|
lines.each do |line|
|
32
32
|
# 644 tom staff 11 2014-11-04 08:29 foo.txt
|
33
|
-
line.
|
33
|
+
expect(line).to match(/^\d{3}\t\w+\t\w+\t\d+\t\d{4}\-\d{2}-\d{2}\t\d{2}:\d{2}\t[\w\.]+$/)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
it "runs grep" do
|
38
38
|
lines = %w{john paul george ringo}
|
39
39
|
out = run("grep(/o[h|r]/)", lines)
|
40
|
-
out.
|
40
|
+
expect(out).to eq("john\ngeorge")
|
41
41
|
end
|
42
42
|
|
43
43
|
it "runs map with two arguments" do
|
44
44
|
lines = %w{john paul george ringo}
|
45
45
|
out = run('map(:[], 0)', lines)
|
46
|
-
out.
|
46
|
+
expect(out).to eq(%w{j p g r}.join("\n"))
|
47
47
|
end
|
48
48
|
|
49
49
|
it "runs sort" do
|
50
50
|
lines = %w{john paul george ringo}
|
51
51
|
out = run('sort', lines)
|
52
|
-
out.
|
52
|
+
expect(out).to eq(lines.sort.join("\n"))
|
53
53
|
end
|
54
54
|
|
55
55
|
it "takes files as arguments" do
|
56
56
|
out = run(['to_s', fixture_path('files', 'foo.txt')])
|
57
|
-
out.
|
57
|
+
expect(out).to eq("foo\nfoo\nfoo")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "runs code prepended by '! '" do
|
61
61
|
out = run('! 2 + 3')
|
62
|
-
out.
|
62
|
+
expect(out).to eq('5')
|
63
63
|
end
|
64
64
|
|
65
65
|
context "no arguments" do
|
66
66
|
it "prints help" do
|
67
|
-
STDERR.
|
68
|
-
out.
|
67
|
+
allow(STDERR).to receive(:puts) do |out|
|
68
|
+
expect(out).to include('Ruby in your shell!')
|
69
69
|
end
|
70
|
-
Ru::Process.
|
70
|
+
allow_any_instance_of(Ru::Process).to receive(:exit).with(1)
|
71
71
|
run('')
|
72
72
|
end
|
73
73
|
end
|
@@ -82,28 +82,28 @@ describe Ru::Process do
|
|
82
82
|
describe "command management" do
|
83
83
|
describe "list" do
|
84
84
|
it "lists the commands" do
|
85
|
-
Ru::CommandManager.
|
85
|
+
allow_any_instance_of(Ru::CommandManager).to receive(:get_commands).and_return({
|
86
86
|
'product' => 'map(:to_i).reduce(:*)',
|
87
87
|
'sum' => 'map(:to_i).sum',
|
88
88
|
})
|
89
89
|
out = run(['list'])
|
90
|
-
out.
|
90
|
+
expect(out).to eq("Saved commands:\nproduct\tmap(:to_i).reduce(:*)\nsum\tmap(:to_i).sum")
|
91
91
|
end
|
92
92
|
|
93
93
|
context "no saved commands" do
|
94
94
|
it "shows a message" do
|
95
|
-
Ru::CommandManager.
|
95
|
+
allow_any_instance_of(Ru::CommandManager).to receive(:get_commands).and_return({})
|
96
96
|
out = run(['list'])
|
97
|
-
out.
|
97
|
+
expect(out).to eq("No saved commands. To save a command, use `save`:\nru save sum 'map(:to_i).sum'")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
describe "run" do
|
103
103
|
it "runs the command" do
|
104
|
-
Ru::CommandManager.
|
104
|
+
allow_any_instance_of(Ru::CommandManager).to receive(:get_commands).and_return({ 'sum' => 'map(:to_i).sum' })
|
105
105
|
out = run(['run', 'sum'], "2\n3")
|
106
|
-
out.
|
106
|
+
expect(out).to eq('5')
|
107
107
|
end
|
108
108
|
|
109
109
|
context "no command name" do
|
@@ -115,7 +115,7 @@ describe Ru::Process do
|
|
115
115
|
|
116
116
|
describe "save" do
|
117
117
|
it "saves the command" do
|
118
|
-
Ru::CommandManager.
|
118
|
+
allow_any_instance_of(Ru::CommandManager).to receive(:save_commands)
|
119
119
|
run(['save', 'foo', 'map(:to_i).sum'])
|
120
120
|
end
|
121
121
|
|
@@ -137,42 +137,42 @@ describe Ru::Process do
|
|
137
137
|
context "-h" do
|
138
138
|
it "shows help" do
|
139
139
|
out = run('--help')
|
140
|
-
out.
|
140
|
+
expect(out).to include('Ruby in your shell!')
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
144
|
context "--help" do
|
145
145
|
it "shows help" do
|
146
146
|
out = run('-h')
|
147
|
-
out.
|
147
|
+
expect(out).to include('Ruby in your shell!')
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
151
|
context "help with a second argument" do
|
152
152
|
it "shows help" do
|
153
153
|
out = run(['--help', 'foo'])
|
154
|
-
out.
|
154
|
+
expect(out).to include('Ruby in your shell!')
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
158
|
context "-v" do
|
159
159
|
it "shows the version" do
|
160
160
|
out = run('-v')
|
161
|
-
out.
|
161
|
+
expect(out).to eq(Ru::VERSION)
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
165
|
context "--version" do
|
166
166
|
it "shows the version" do
|
167
167
|
out = run('--version')
|
168
|
-
out.
|
168
|
+
expect(out).to eq(Ru::VERSION)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
172
|
context "version with a second argument" do
|
173
173
|
it "shows the version" do
|
174
174
|
out = run(['--version', 'foo'])
|
175
|
-
out.
|
175
|
+
expect(out).to eq(Ru::VERSION)
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Benner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: appraisal
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.1'
|
55
55
|
description: Ruby in your shell!
|
56
56
|
email:
|
57
57
|
- tombenner@gmail.com
|