rubyc 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +101 -56
- data/Rakefile +12 -3
- data/lib/rubyc/cli.rb +27 -15
- data/lib/rubyc/core_extensions.rb +2 -20
- data/lib/rubyc/version.rb +1 -1
- data/rubyc.gemspec +2 -2
- data/spec/cli_spec.rb +27 -27
- data/spec/spec_helper.rb +7 -9
- metadata +27 -50
- data/lib/rubyc/colorize_stack.rb +0 -37
- data/spec/colorize_stack_spec.rb +0 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 129a515517a551a55fb60a6c2af06819da814828e9dd9a4328532e27a90553e3
|
4
|
+
data.tar.gz: 6d5dff8eb1ab16c468045138b7b4a011755abc0b62ef4240cf55ebffb27d35c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebcf9c8df0fbdcd5e5b59f075f288773da129a0588dd13dadb4d0b82a860aed3c88ed92df33cae58b0ba22303ae8261179f0be04f70072d0d24a9e4ac432710a
|
7
|
+
data.tar.gz: 60138e7cacccc60efd625f81b770d30b21932953801ea68f3f1cfb364d8adfc78328f6791c7eded23f1038243755278e7b7736d37f7ab2792d6656b9683f45b5
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,64 +1,104 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubyc (0.
|
4
|
+
rubyc (0.3.0)
|
5
5
|
thor (~> 0.15)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
archive-tar-minitar (0.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
10
|
+
archive-tar-minitar (0.8)
|
11
|
+
minitar (~> 0.8)
|
12
|
+
minitar-cli (~> 0.8)
|
13
|
+
aruba (0.14.14)
|
14
|
+
childprocess (>= 0.6.3, < 4.0.0)
|
15
|
+
contracts (~> 0.9)
|
16
|
+
cucumber (>= 1.3.19)
|
17
|
+
ffi (~> 1.9)
|
18
|
+
rspec-expectations (>= 2.99)
|
19
|
+
thor (>= 0.19, < 2.0)
|
20
|
+
builder (3.2.4)
|
21
|
+
childprocess (3.0.0)
|
22
|
+
coderay (1.1.3)
|
23
|
+
colorize (0.8.1)
|
24
|
+
columnize (0.9.0)
|
25
|
+
contracts (0.16.1)
|
26
|
+
cucumber (8.0.0)
|
27
|
+
builder (~> 3.2, >= 3.2.4)
|
28
|
+
cucumber-ci-environment (~> 9.0, >= 9.0.4)
|
29
|
+
cucumber-core (~> 11.0, >= 11.0.0)
|
30
|
+
cucumber-cucumber-expressions (~> 15.1, >= 15.1.1)
|
31
|
+
cucumber-gherkin (~> 23.0, >= 23.0.1)
|
32
|
+
cucumber-html-formatter (~> 19.1, >= 19.1.0)
|
33
|
+
cucumber-messages (~> 18.0, >= 18.0.0)
|
34
|
+
diff-lcs (~> 1.5, >= 1.5.0)
|
35
|
+
mime-types (~> 3.4, >= 3.4.1)
|
36
|
+
multi_test (~> 1.1, >= 1.1.0)
|
37
|
+
sys-uname (~> 1.2, >= 1.2.2)
|
38
|
+
cucumber-ci-environment (9.0.4)
|
39
|
+
cucumber-core (11.0.0)
|
40
|
+
cucumber-gherkin (~> 23.0, >= 23.0.1)
|
41
|
+
cucumber-messages (~> 18.0, >= 18.0.0)
|
42
|
+
cucumber-tag-expressions (~> 4.1, >= 4.1.0)
|
43
|
+
cucumber-cucumber-expressions (15.2.0)
|
44
|
+
cucumber-gherkin (23.0.1)
|
45
|
+
cucumber-messages (~> 18.0, >= 18.0.0)
|
46
|
+
cucumber-html-formatter (19.2.0)
|
47
|
+
cucumber-messages (~> 18.0, >= 18.0.0)
|
48
|
+
cucumber-messages (18.0.0)
|
49
|
+
cucumber-tag-expressions (4.1.0)
|
50
|
+
diff-lcs (1.5.0)
|
51
|
+
ffi (1.15.5)
|
52
|
+
formatador (1.1.0)
|
53
|
+
growl (1.0.3)
|
54
|
+
guard (2.18.0)
|
55
|
+
formatador (>= 0.2.4)
|
56
|
+
listen (>= 2.7, < 4.0)
|
57
|
+
lumberjack (>= 1.0.12, < 2.0)
|
58
|
+
nenv (~> 0.1)
|
59
|
+
notiffany (~> 0.0)
|
60
|
+
pry (>= 0.13.0)
|
61
|
+
shellany (~> 0.0)
|
62
|
+
thor (>= 0.18.1)
|
63
|
+
guard-compat (1.2.1)
|
64
|
+
guard-minitest (2.4.6)
|
65
|
+
guard-compat (~> 1.2)
|
66
|
+
minitest (>= 3.0)
|
67
|
+
hashie (5.0.0)
|
68
|
+
linecache (1.3.1)
|
41
69
|
linecache19 (0.5.12)
|
42
70
|
ruby_core_source (>= 0.1.4)
|
43
|
-
listen (
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
listen (3.7.1)
|
72
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
73
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
74
|
+
lumberjack (1.2.8)
|
75
|
+
method_source (1.0.0)
|
76
|
+
mime-types (3.4.1)
|
77
|
+
mime-types-data (~> 3.2015)
|
78
|
+
mime-types-data (3.2022.0105)
|
79
|
+
minitar (0.8)
|
80
|
+
minitar-cli (0.8)
|
81
|
+
minitar (~> 0.8.0)
|
82
|
+
powerbar (~> 1.0)
|
83
|
+
minitest (5.16.1)
|
84
|
+
multi_test (1.1.0)
|
85
|
+
nenv (0.3.0)
|
86
|
+
notiffany (0.1.3)
|
87
|
+
nenv (~> 0.1)
|
88
|
+
shellany (~> 0.0)
|
89
|
+
powerbar (1.0.18)
|
90
|
+
hashie (>= 1.1.0)
|
91
|
+
pry (0.14.1)
|
92
|
+
coderay (~> 1.1)
|
93
|
+
method_source (~> 1.0)
|
94
|
+
rake (13.0.6)
|
95
|
+
rb-fsevent (0.11.1)
|
96
|
+
rb-inotify (0.10.1)
|
97
|
+
ffi (~> 1.0)
|
98
|
+
rspec-expectations (3.11.0)
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
+
rspec-support (~> 3.11.0)
|
101
|
+
rspec-support (3.11.0)
|
62
102
|
ruby-debug (0.10.4)
|
63
103
|
columnize (>= 0.1)
|
64
104
|
ruby-debug-base (~> 0.10.4.0)
|
@@ -74,17 +114,20 @@ GEM
|
|
74
114
|
ruby-debug-base19 (>= 0.11.19)
|
75
115
|
ruby_core_source (0.1.5)
|
76
116
|
archive-tar-minitar (>= 0.5.2)
|
77
|
-
|
78
|
-
|
79
|
-
|
117
|
+
shellany (0.0.1)
|
118
|
+
sys-uname (1.2.2)
|
119
|
+
ffi (~> 1.1)
|
120
|
+
thor (0.20.3)
|
80
121
|
|
81
122
|
PLATFORMS
|
82
123
|
ruby
|
124
|
+
x86_64-darwin-19
|
83
125
|
|
84
126
|
DEPENDENCIES
|
85
127
|
aruba
|
86
|
-
bundler (~>
|
128
|
+
bundler (~> 2.0)
|
87
129
|
colorize
|
130
|
+
growl
|
88
131
|
guard
|
89
132
|
guard-minitest
|
90
133
|
minitest
|
@@ -93,5 +136,7 @@ DEPENDENCIES
|
|
93
136
|
rb-fsevent
|
94
137
|
ruby-debug (>= 0.10.3)
|
95
138
|
ruby-debug19
|
96
|
-
ruby_gntp
|
97
139
|
rubyc!
|
140
|
+
|
141
|
+
BUNDLED WITH
|
142
|
+
2.3.17
|
data/Rakefile
CHANGED
@@ -6,11 +6,20 @@ require 'rake/testtask'
|
|
6
6
|
require 'cucumber'
|
7
7
|
require 'cucumber/rake/task'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
require "minitest/test_task"
|
10
|
+
|
11
|
+
Minitest::TestTask.create # named test, sensible defaults
|
12
|
+
|
13
|
+
# or more explicitly:
|
14
|
+
|
15
|
+
Minitest::TestTask.create(:test) do |t|
|
16
|
+
t.libs << "spec"
|
17
|
+
t.libs << "lib"
|
18
|
+
t.warning = false
|
19
|
+
t.test_globs = ["test/**/*_spec.rb"]
|
12
20
|
end
|
13
21
|
|
22
|
+
|
14
23
|
Cucumber::Rake::Task.new(:features) do |t|
|
15
24
|
t.fork = false
|
16
25
|
end
|
data/lib/rubyc/cli.rb
CHANGED
@@ -1,33 +1,35 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "yaml"
|
2
|
+
require "thor"
|
3
|
+
require "rubyc/core_extensions"
|
4
4
|
|
5
5
|
module Rubyc
|
6
6
|
class CLI < Thor
|
7
|
-
class_option :require, :aliases =>
|
8
|
-
class_option :sync, :type => :boolean, :default => false, :aliases =>
|
7
|
+
class_option :require, :aliases => "-r"
|
8
|
+
class_option :sync, :type => :boolean, :default => false, :aliases => "-s", :banner => "Synchronize stdout"
|
9
9
|
|
10
10
|
def initialize(*args)
|
11
11
|
super
|
12
12
|
libs = options[:require] ? options[:require].strip.split(":") : []
|
13
|
-
libs.each {|lib| require lib}
|
13
|
+
libs.each { |lib| require lib }
|
14
14
|
$stdout.sync = options[:sync]
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def help(*args)
|
18
|
-
super
|
18
|
+
super(*args)
|
19
19
|
end
|
20
20
|
|
21
21
|
desc "map BLOCK", "Enumerable#map"
|
22
|
-
long_desc "THIS IS A LONG DESCRIPTION"
|
22
|
+
long_desc "THIS IS A LONG DESCRIPTION"
|
23
|
+
|
23
24
|
def map(code)
|
24
|
-
proc = eval(
|
25
|
+
proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
|
25
26
|
$stdin.each_line.each_with_index do |line, index|
|
26
27
|
puts proc.call(line.chomp, index).to_s
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
desc "sum BLOCK", "Active Support Enumerable#sum"
|
32
|
+
|
31
33
|
def sum(code = nil)
|
32
34
|
code ||= "line"
|
33
35
|
proc = eval("Proc.new{|line| l = line; #{code}}")
|
@@ -38,22 +40,25 @@ module Rubyc
|
|
38
40
|
end
|
39
41
|
|
40
42
|
desc "select BLOCK", "Enumerable#select"
|
43
|
+
|
41
44
|
def select(code)
|
42
|
-
proc = eval(
|
45
|
+
proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
|
43
46
|
$stdin.each_line.each_with_index do |line, index|
|
44
47
|
puts line if proc.call(line.chomp, index)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
51
|
desc "reject BLOCK", "Enumerable#reject"
|
52
|
+
|
49
53
|
def reject(code)
|
50
|
-
proc = eval(
|
54
|
+
proc = eval("Proc.new{|line,index| l = line; lnum = index + 1;#{code}}")
|
51
55
|
$stdin.each_line.each_with_index do |line, index|
|
52
56
|
puts line unless proc.call(line.chomp, index)
|
53
57
|
end
|
54
58
|
end
|
55
|
-
|
59
|
+
|
56
60
|
desc "count_by BLOCK", "Count the number of lines that have the same property. The property is defined by the return value of the given the block"
|
61
|
+
|
57
62
|
def count_by(code = nil)
|
58
63
|
code ||= "line"
|
59
64
|
proc = eval("Proc.new{|line| l = line; #{code}}")
|
@@ -64,6 +69,7 @@ module Rubyc
|
|
64
69
|
end
|
65
70
|
|
66
71
|
desc "sort_by BLOCK", "Enumerable#sort_by"
|
72
|
+
|
67
73
|
def sort_by(code = nil)
|
68
74
|
code ||= "line"
|
69
75
|
proc = eval("Proc.new{|line| l = line; #{code}}")
|
@@ -74,6 +80,7 @@ module Rubyc
|
|
74
80
|
end
|
75
81
|
|
76
82
|
desc "grep BLOCK", "Enumerable#grep"
|
83
|
+
|
77
84
|
def grep(pattern, code = nil)
|
78
85
|
pattern = eval(pattern)
|
79
86
|
proc = code ? eval("Proc.new{|line| l = line; #{code}}") : nil
|
@@ -81,6 +88,7 @@ module Rubyc
|
|
81
88
|
end
|
82
89
|
|
83
90
|
desc "scan MATCHER BLOCK", "String#scan"
|
91
|
+
|
84
92
|
def scan(pattern, code = nil)
|
85
93
|
pattern = eval(pattern)
|
86
94
|
proc = code ? eval("Proc.new{|*match| m = match; #{code}}") : nil
|
@@ -89,11 +97,13 @@ module Rubyc
|
|
89
97
|
end
|
90
98
|
|
91
99
|
desc "uniq", "Enumerable#uniq"
|
100
|
+
|
92
101
|
def uniq
|
93
102
|
puts $stdin.to_a.uniq
|
94
103
|
end
|
95
104
|
|
96
105
|
desc "uniq_by BLOCK", "TODO"
|
106
|
+
|
97
107
|
def uniq_by(code = nil)
|
98
108
|
code ||= "line"
|
99
109
|
proc = eval("Proc.new{|line| l = line; #{code}}")
|
@@ -104,13 +114,15 @@ module Rubyc
|
|
104
114
|
end
|
105
115
|
|
106
116
|
desc "compact", "Remove empty lines"
|
117
|
+
|
107
118
|
def compact
|
108
|
-
$stdin.each{ |line| puts line if line.chomp! != ""}
|
119
|
+
$stdin.each { |line| puts line if line.chomp! != "" }
|
109
120
|
end
|
110
121
|
|
111
122
|
desc "merge NB_LINES [SEPARATOR]", "Merge NB_LINES consecutive lines using SEPARATOR. If SEPARATOR is not given \',\' is used"
|
123
|
+
|
112
124
|
def merge(nb_lines, sep = ",")
|
113
|
-
$stdin.each_slice(nb_lines.to_i){|chunk| puts chunk.map{|elem| elem.strip}.join(sep)}
|
125
|
+
$stdin.each_slice(nb_lines.to_i) { |chunk| puts chunk.map { |elem| elem.strip }.join(sep) }
|
114
126
|
end
|
115
127
|
end
|
116
128
|
end
|
@@ -8,29 +8,11 @@ module Enumerable
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
# This method was borrowed from ActiveSupport code
|
12
|
-
def group_by
|
13
|
-
self.inject({}) do |memo, elem|
|
14
|
-
key = yield elem
|
15
|
-
memo[key] ||= []
|
16
|
-
memo[key] << elem
|
17
|
-
memo
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 57
|
22
|
-
def sum(identity = 0, &block)
|
23
|
-
if block_given?
|
24
|
-
map(&block).sum(identity)
|
25
|
-
else
|
26
|
-
inject { |sum, element| sum + element } || identity
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
11
|
def uniq_by
|
31
|
-
|
12
|
+
each_with_index.inject({}) do |memo, (obj, index)|
|
32
13
|
val, data = yield obj
|
33
14
|
memo[val] ||= data
|
15
|
+
memo
|
34
16
|
end.values
|
35
17
|
end
|
36
18
|
end
|
data/lib/rubyc/version.rb
CHANGED
data/rubyc.gemspec
CHANGED
@@ -7,15 +7,15 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Rubyc::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Martin Chabot"]
|
10
|
+
s.licenses = ["MIT"]
|
10
11
|
s.email = ["chabotm@gmail.com"]
|
11
12
|
s.homepage = "https://github.com/martinos/rubyc"
|
12
13
|
s.summary = %q{Adds Ruby's powers to the command line}
|
13
14
|
s.description = %q{Adds Ruby's powers to the command line}
|
14
|
-
s.rubyforge_project = "rubyc"
|
15
15
|
|
16
16
|
s.add_dependency "thor", "~> 0.15"
|
17
17
|
s.add_development_dependency 'rake'
|
18
|
-
s.add_development_dependency "bundler", "~>
|
18
|
+
s.add_development_dependency "bundler", "~> 2.0"
|
19
19
|
s.add_development_dependency 'minitest'
|
20
20
|
s.add_development_dependency 'aruba'
|
21
21
|
s.add_development_dependency 'colorize'
|
data/spec/cli_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "rubyc/cli"
|
3
3
|
|
4
4
|
include SpecHelper
|
5
5
|
|
@@ -12,94 +12,94 @@ describe "A rubyc cli" do
|
|
12
12
|
out_str = local_io("first\nsecond") do
|
13
13
|
@cli.map('"LineNum=#{lnum} Index=#{index}: #{l.upcase}"')
|
14
14
|
end
|
15
|
-
out_str.must_equal "LineNum=1 Index=0: FIRST\nLineNum=2 Index=1: SECOND\n"
|
15
|
+
_(out_str).must_equal "LineNum=1 Index=0: FIRST\nLineNum=2 Index=1: SECOND\n"
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should select line from stdin and send it to stdout" do
|
19
19
|
out_str = local_io("John Doe\nBlack Jack\nDr Dolittle\nCracker Jack") do
|
20
|
-
@cli.select(
|
20
|
+
@cli.select("l =~ /Jack/ && lnum == 2 && index == 1")
|
21
21
|
end
|
22
|
-
out_str.must_equal "Black Jack\n"
|
22
|
+
_(out_str).must_equal "Black Jack\n"
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should reject line from stdin and send it to stdout" do
|
26
26
|
out_str = local_io("John Doe\nBlack Jack\nDr Dolittle\nCracker Jack") do
|
27
|
-
@cli.reject(
|
27
|
+
@cli.reject("l =~ /Jack/ && lnum == 2 && index == 1")
|
28
28
|
end
|
29
|
-
out_str.must_equal "John Doe\nDr Dolittle\nCracker Jack\n"
|
29
|
+
_(out_str).must_equal "John Doe\nDr Dolittle\nCracker Jack\n"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should sum line from stdin and send it to stdout" do
|
33
33
|
out_str = local_io("1\n2\nthird\n4") do
|
34
|
-
@cli.sum(
|
34
|
+
@cli.sum("l.to_i * 2")
|
35
35
|
end
|
36
|
-
out_str.must_equal "14\n"
|
36
|
+
_(out_str).must_equal "14\n"
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should sort by stdin and send the result to stdout" do
|
40
40
|
out_str = local_io("a\nbbb\ncc\ndddd") do
|
41
|
-
@cli.sort_by(
|
41
|
+
@cli.sort_by("l.length")
|
42
42
|
end
|
43
|
-
out_str.must_equal "a\ncc\nbbb\ndddd\n"
|
43
|
+
_(out_str).must_equal "a\ncc\nbbb\ndddd\n"
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should grep stdin and send the result to stdout" do
|
47
47
|
out_str = local_io("bbbb\nbbb\ncc\ndddd") do
|
48
|
-
@cli.grep(
|
48
|
+
@cli.grep("/^b/", "l.upcase")
|
49
49
|
end
|
50
|
-
out_str.must_equal "BBBB\nBBB\n"
|
50
|
+
_(out_str).must_equal "BBBB\nBBB\n"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should count_by an algorithm and output to stdout" do
|
54
54
|
out_str = local_io("bbbb\nbbb\ncc\ndddd") do
|
55
|
-
@cli.count_by(
|
56
|
-
end
|
57
|
-
expected = {"bb" => 2, "cc" => 1, "dd" => 1}
|
55
|
+
@cli.count_by("l =~ /^(..)/;$1")
|
56
|
+
end
|
57
|
+
expected = { "bb" => 2, "cc" => 1, "dd" => 1 }
|
58
58
|
|
59
|
-
YAML.load(out_str).must_equal expected
|
59
|
+
_(YAML.load(out_str)).must_equal expected
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should remove empty lines from stdin and output to stdout" do
|
63
|
-
out_str = local_io("bbbb\n\ncc\n") do
|
63
|
+
out_str = local_io("bbbb\n\ncc\n") do
|
64
64
|
@cli.compact
|
65
65
|
end
|
66
|
-
out_str.must_equal "bbbb\ncc\n"
|
66
|
+
_(out_str).must_equal "bbbb\ncc\n"
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should keep unique lines from stdin and output them to stdout" do
|
70
70
|
out_str = local_io("1\n2\n2\n3") do
|
71
71
|
@cli.uniq
|
72
72
|
end
|
73
|
-
out_str.must_equal "1\n2\n3\n"
|
73
|
+
_(out_str).must_equal "1\n2\n3\n"
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should keep unique records grouped by a certain algorithm" do
|
77
77
|
out_str = local_io("aaaCoco\nbbbMomo\naaaBato\nbbbToto") do
|
78
|
-
@cli.uniq_by(
|
78
|
+
@cli.uniq_by("[l[0,3], l[3..-1]]")
|
79
79
|
end
|
80
|
-
|
80
|
+
# We test this way since uniq_by uses hashes and on Ruby 1.8.7 hashes are not ordered
|
81
|
+
out_array = out_str.split("\n").sort
|
82
|
+
_(out_array).must_equal ["Coco", "Momo"]
|
81
83
|
end
|
82
84
|
|
83
85
|
it "should merge lines in group of n output them to stdout" do
|
84
86
|
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
85
87
|
@cli.merge(3, ",")
|
86
88
|
end
|
87
|
-
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
89
|
+
_(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
|
88
90
|
end
|
89
91
|
|
90
|
-
|
91
92
|
it "should merge lines in group of n output them to stdout" do
|
92
93
|
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
93
94
|
@cli.merge(3, ",")
|
94
95
|
end
|
95
|
-
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
96
|
+
_(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
|
96
97
|
end
|
97
98
|
|
98
99
|
it "should merge lines in group of n output them to stdout" do
|
99
100
|
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
100
101
|
@cli.merge(3, ",")
|
101
102
|
end
|
102
|
-
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
103
|
+
_(out_str).must_equal "1,2,3\n4,5,6\n7,8\n"
|
103
104
|
end
|
104
105
|
end
|
105
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
$:.unshift File.expand_path(
|
2
|
-
$:.unshift File.expand_path(
|
3
|
-
ROOT_PATH = File.expand_path(
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require 'rubyc/colorize_stack'
|
1
|
+
$:.unshift File.expand_path("..", __FILE__)
|
2
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
3
|
+
ROOT_PATH = File.expand_path("../..", __FILE__)
|
4
|
+
require "rubyc"
|
5
|
+
require "minitest/spec"
|
6
|
+
require "minitest/autorun"
|
8
7
|
|
9
8
|
module SpecHelper
|
10
9
|
def local_io(in_str)
|
11
|
-
old_stdin, old_stdout = $stdin, $stdout
|
10
|
+
old_stdin, old_stdout = $stdin, $stdout
|
12
11
|
$stdin = StringIO.new(in_str)
|
13
12
|
$stdout = StringIO.new
|
14
13
|
yield
|
@@ -17,4 +16,3 @@ module SpecHelper
|
|
17
16
|
out_str
|
18
17
|
end
|
19
18
|
end
|
20
|
-
MiniTest::Unit.output.extend MiniTest::ColorizeStack
|
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Martin Chabot
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-06-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: thor
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0.15'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0.15'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: bundler
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '2.0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
54
|
+
version: '2.0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: minitest
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: aruba
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: colorize
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - ">="
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - ">="
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: Adds Ruby's powers to the command line
|
@@ -115,7 +102,7 @@ executables:
|
|
115
102
|
extensions: []
|
116
103
|
extra_rdoc_files: []
|
117
104
|
files:
|
118
|
-
- .gitignore
|
105
|
+
- ".gitignore"
|
119
106
|
- Gemfile
|
120
107
|
- Gemfile.lock
|
121
108
|
- Guardfile
|
@@ -132,42 +119,33 @@ files:
|
|
132
119
|
- features/support/env.rb
|
133
120
|
- lib/rubyc.rb
|
134
121
|
- lib/rubyc/cli.rb
|
135
|
-
- lib/rubyc/colorize_stack.rb
|
136
122
|
- lib/rubyc/core_extensions.rb
|
137
123
|
- lib/rubyc/version.rb
|
138
124
|
- rubyc.gemspec
|
139
125
|
- spec/cli_spec.rb
|
140
|
-
- spec/colorize_stack_spec.rb
|
141
126
|
- spec/spec_helper.rb
|
142
127
|
homepage: https://github.com/martinos/rubyc
|
143
|
-
licenses:
|
144
|
-
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
145
132
|
rdoc_options: []
|
146
133
|
require_paths:
|
147
134
|
- lib
|
148
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
136
|
requirements:
|
151
|
-
- -
|
137
|
+
- - ">="
|
152
138
|
- !ruby/object:Gem::Version
|
153
139
|
version: '0'
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
hash: -3499535431891997109
|
157
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
-
none: false
|
159
141
|
requirements:
|
160
|
-
- -
|
142
|
+
- - ">="
|
161
143
|
- !ruby/object:Gem::Version
|
162
144
|
version: '0'
|
163
|
-
segments:
|
164
|
-
- 0
|
165
|
-
hash: -3499535431891997109
|
166
145
|
requirements: []
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
specification_version: 3
|
146
|
+
rubygems_version: 3.1.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
171
149
|
summary: Adds Ruby's powers to the command line
|
172
150
|
test_files:
|
173
151
|
- features/fixtures/file1.csv
|
@@ -178,5 +156,4 @@ test_files:
|
|
178
156
|
- features/step_definitions/rubyc_steps.rb
|
179
157
|
- features/support/env.rb
|
180
158
|
- spec/cli_spec.rb
|
181
|
-
- spec/colorize_stack_spec.rb
|
182
159
|
- spec/spec_helper.rb
|
data/lib/rubyc/colorize_stack.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module MiniTest
|
2
|
-
# http://blog.macromates.com/2007/the-textmate-url-scheme/
|
3
|
-
module ColorizeStack
|
4
|
-
def write(str = "")
|
5
|
-
str.each_line do |line|
|
6
|
-
super(colorize_line(line))
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def colorize_line(line)
|
11
|
-
red = "\e[31m"
|
12
|
-
clear = "\e[0m"
|
13
|
-
green = "\e[32m"
|
14
|
-
blue = "\e[34m"
|
15
|
-
magenta = "\e[35m"
|
16
|
-
clear = "\e[0m"
|
17
|
-
# test_0001_should_map_stdin_to_stdout(A rubyc cli) [./spec/cli_spec.rb:16]:
|
18
|
-
# /Users/martinchabot/dev/my_gems/rubyc/spec/cli_spec.rb:16:in `test_0001_should_map_stdin_to_stdout'
|
19
|
-
url_regex = /(.*?)([.\w\/]*.rb):(\d+)(.*)/
|
20
|
-
if line =~ url_regex
|
21
|
-
prefix, file_name, line_number, suffix = $1, $2, $3, $4
|
22
|
-
if File.exist? file_name
|
23
|
-
full_path = File.expand_path(file_name)
|
24
|
-
app_trace = full_path.match(Dir.pwd) && full_path !~ /vendor/
|
25
|
-
new_line = "#{prefix}#{blue}txmt://open?url=file://#{File.dirname(full_path)}/#{clear}#{red if app_trace }#{File.basename(full_path)}#{clear if app_trace}&line=#{line_number}#{suffix}\n"
|
26
|
-
else
|
27
|
-
new_line = line
|
28
|
-
end
|
29
|
-
else
|
30
|
-
new_line = line
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
|
data/spec/colorize_stack_spec.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'stringio'
|
3
|
-
|
4
|
-
|
5
|
-
describe MiniTest::ColorizeStack do
|
6
|
-
it 'shoud colorize IO' do
|
7
|
-
str = <<EOF
|
8
|
-
test_0003_should_return_the_value_from_on_key(AProductionBafFileSpec::AStructureSpec):
|
9
|
-
RuntimeError: THIS IS A STACKTRACE TEST
|
10
|
-
./lib/rubyc/colorize_stack.rb:19:in `extract_data_from_raw'
|
11
|
-
./lib/rubyc/colorize_stack.rb:9:in `initialize'
|
12
|
-
./lib/rubyc/colorize_stack.rb:44:in `new'
|
13
|
-
./lib/rubyc/colorize_stack.rb:44:in `parse'
|
14
|
-
./lib/rubyc/core_extensions.rb:18:in `parse'
|
15
|
-
./lib/rubyc/core_extensions.rb:17:in `map'
|
16
|
-
./lib/rubyc/core_extensions.rb:17:in `parse'
|
17
|
-
./lib/rubyc/core_extensions.rb:26:in `parse'
|
18
|
-
./lib/rubyc/core_extensions.rb:39:in `scanned_string'
|
19
|
-
./lib/rubyc/core_extensions.rb:16:in `parse'
|
20
|
-
./lib/rubyc/core_extensions.rb:27:in `read'
|
21
|
-
./spec/spec_helper.rb:8
|
22
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/spec.rb:118:in `instance_eval'
|
23
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/spec.rb:118:in `setup'
|
24
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:713:in `run'
|
25
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:675:in `run_test_suites'
|
26
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:669:in `each'
|
27
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:669:in `run_test_suites'
|
28
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:668:in `each'
|
29
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:668:in `run_test_suites'
|
30
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:632:in `run'
|
31
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352/gems/minitest-1.7.2/lib/minitest/unit.rb:524:in `autorun'
|
32
|
-
/Users/martinos/.rvm/gems/ruby-1.8.7-p352@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
|
33
|
-
|
34
|
-
5 tests, 0 assertions, 0 failures, 5 errors, 0 skips
|
35
|
-
EOF
|
36
|
-
out = StringIO.new
|
37
|
-
out.extend MiniTest::ColorizeStack
|
38
|
-
out.write(str)
|
39
|
-
str = out.string
|
40
|
-
red = "\e\\[31m"
|
41
|
-
clear = "\e\\[0m"
|
42
|
-
green = "\e\\[32m"
|
43
|
-
blue = "\e\\[34m"
|
44
|
-
magenta = "\e\\[35m"
|
45
|
-
str.must_match %r{txmt://open\?url=file:///(.*)rubyc/lib/rubyc/(.*)colorize_stack.rb(.*)line=19:in `extract_data_from_raw}
|
46
|
-
end
|
47
|
-
end
|