ru 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/gemfiles/activesupport_3.gemfile.lock +1 -1
- data/gemfiles/activesupport_4.gemfile.lock +1 -1
- data/lib/ru/command_manager.rb +4 -0
- data/lib/ru/process.rb +17 -5
- data/lib/ru/version.rb +1 -1
- data/spec/lib/process_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a41f9be8b0fdd59101fe4bba93e8674995f6d871
|
4
|
+
data.tar.gz: e962cc943758d9423fefac4e8a04854e4293aba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ffec1a6d481e9cc429b3383b0f50f1cf2baae7cfdb8d354c4f70daf36f5021ea470b7366d9ebb4749ea213c9a21c0531bb046ce5d7ed7ea783586e8bf125057
|
7
|
+
data.tar.gz: 3aa63965b871d3a09012f60b4457e4950072df4b08a237b388270622e92fd781f623e69a30450280805735d37176c8d7e253ecbb3fe7d223322fd6d50f959521
|
data/README.md
CHANGED
data/lib/ru/command_manager.rb
CHANGED
data/lib/ru/process.rb
CHANGED
@@ -14,11 +14,18 @@ module Ru
|
|
14
14
|
args = ARGV
|
15
15
|
first_arg = args.shift
|
16
16
|
|
17
|
-
if first_arg == '
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
if first_arg == 'list'
|
18
|
+
commands = @command_manager.all
|
19
|
+
if commands.present?
|
20
|
+
lines = ['Saved commands:']
|
21
|
+
lines += commands.sort_by(&:first).map { |name, code| "#{name}\t#{code}" }
|
22
|
+
else
|
23
|
+
lines = [
|
24
|
+
'No saved commands. To save a command, use `save`:',
|
25
|
+
"ru save sum 'map(:to_i).sum'"
|
26
|
+
]
|
27
|
+
end
|
28
|
+
return lines.join("\n")
|
22
29
|
elsif first_arg == 'run'
|
23
30
|
name = args.shift
|
24
31
|
@code = @command_manager.get(name)
|
@@ -27,6 +34,11 @@ module Ru
|
|
27
34
|
exit 1
|
28
35
|
return
|
29
36
|
end
|
37
|
+
elsif first_arg == 'save'
|
38
|
+
name = args[0]
|
39
|
+
code = args[1]
|
40
|
+
@command_manager.save(name, code)
|
41
|
+
return "Saved command: #{name} is '#{code}'"
|
30
42
|
elsif first_arg.blank?
|
31
43
|
STDERR.puts @option_printer.run(:help)
|
32
44
|
exit 1
|
data/lib/ru/version.rb
CHANGED
data/spec/lib/process_spec.rb
CHANGED
@@ -80,6 +80,25 @@ describe Ru::Process do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "command management" do
|
83
|
+
describe "list" do
|
84
|
+
it "lists the commands" do
|
85
|
+
Ru::CommandManager.any_instance.stub(:get_commands).and_return({
|
86
|
+
'product' => 'map(:to_i).reduce(:*)',
|
87
|
+
'sum' => 'map(:to_i).sum',
|
88
|
+
})
|
89
|
+
out = run(['list'])
|
90
|
+
out.should == "Saved commands:\nproduct\tmap(:to_i).reduce(:*)\nsum\tmap(:to_i).sum"
|
91
|
+
end
|
92
|
+
|
93
|
+
context "no saved commands" do
|
94
|
+
it "shows a message" do
|
95
|
+
Ru::CommandManager.any_instance.stub(:get_commands).and_return({})
|
96
|
+
out = run(['list'])
|
97
|
+
out.should == "No saved commands. To save a command, use `save`:\nru save sum 'map(:to_i).sum'"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
83
102
|
describe "run" do
|
84
103
|
it "runs the command" do
|
85
104
|
Ru::CommandManager.any_instance.stub(:get_commands).and_return({ 'sum' => 'map(:to_i).sum' })
|