pru 0.1.5 → 0.1.6
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.
- data/Readme.md +9 -2
- data/VERSION +1 -1
- data/bin/pru +29 -3
- data/pru.gemspec +3 -3
- data/spec/pru_spec.rb +32 -0
- metadata +5 -5
data/Readme.md
CHANGED
@@ -4,7 +4,7 @@ Install
|
|
4
4
|
=======
|
5
5
|
sudo gem install pru
|
6
6
|
|
7
|
-
Working with rvm / many gemsets -> only install once
|
7
|
+
Working with rvm / many gemsets -> only install once
|
8
8
|
|
9
9
|
rvm 1.9.2 exec gem install pru
|
10
10
|
echo 'alias pru="rvm 1.9.2 exec pru"' >> ~/.bash_profile
|
@@ -24,6 +24,7 @@ Reduce works on all lines as Array<br/>
|
|
24
24
|
|
25
25
|
-I, --libdir DIR Add DIR to load path
|
26
26
|
--require LIB Require LIB (also comma-separated)
|
27
|
+
-i, --inplace-edit FILE Edit FILE inplace
|
27
28
|
|
28
29
|
-h, --help Show this.
|
29
30
|
-v, --version Show Version
|
@@ -52,7 +53,7 @@ Reduce works on all lines as Array<br/>
|
|
52
53
|
|
53
54
|
# wc --- count lines
|
54
55
|
ls -al | wc -l
|
55
|
-
ls -al | pru --
|
56
|
+
ls -al | pru --reduce 'size'
|
56
57
|
|
57
58
|
# sed -- replace a 5 with five
|
58
59
|
ls -al | sed 's/5/five/'
|
@@ -70,6 +71,12 @@ Reduce works on all lines as Array<br/>
|
|
70
71
|
# quotes inside a string
|
71
72
|
something | pru 'include?(%{"string"})'
|
72
73
|
|
74
|
+
# Find a gem version matching a requirement e.g. ~> 1.0.0
|
75
|
+
curl http://rubygems.org/api/v1/versions/bundler | pru --require json 'JSON.parse(self).map{|g|g["number"]}.find{|v| Gem::Requirement.new("~>1.0.1").satisfied_by? Gem::Version.new(v) }'
|
76
|
+
|
77
|
+
# Cleanup strange whitespace in a file
|
78
|
+
pru -i Rakefile 'gsub(/\r\n/,"\n").gsub(/\t/," ")'
|
79
|
+
|
73
80
|
Authors
|
74
81
|
=======
|
75
82
|
### [Contributors](http://github.com/grosser/pru/contributors)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/bin/pru
CHANGED
@@ -4,7 +4,9 @@ require 'optparse'
|
|
4
4
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
5
5
|
require 'pru'
|
6
6
|
|
7
|
+
usage = nil
|
7
8
|
options = {}
|
9
|
+
|
8
10
|
OptionParser.new do |opts|
|
9
11
|
opts.banner = <<BANNER
|
10
12
|
Pipeable Ruby
|
@@ -32,20 +34,44 @@ BANNER
|
|
32
34
|
end
|
33
35
|
lib.split(',').each{|l| require l }
|
34
36
|
}
|
37
|
+
opts.on('-i', '--inplace-edit FILE', 'Edit FILE inplace') { |file| options[:file] = file }
|
35
38
|
opts.separator ''
|
36
39
|
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
37
40
|
opts.on('-v', '--version','Show Version'){ puts Pru::VERSION; exit}
|
41
|
+
usage = opts
|
38
42
|
end.parse!
|
39
43
|
|
44
|
+
if ARGV.empty? and options.empty? # no arguments -> show usage
|
45
|
+
puts usage
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
40
49
|
abort "Too many arguments, see --help" if ARGV.size > 2
|
50
|
+
|
41
51
|
map, reduce = ARGV
|
42
52
|
reduce ||= options[:reduce]
|
43
53
|
map = 'true' if not map or map.empty?
|
44
54
|
|
55
|
+
if options[:file]
|
56
|
+
output_lines = []
|
57
|
+
input = File.read(options[:file])
|
58
|
+
newline = input[/\r\n|\r|\n/]
|
59
|
+
else
|
60
|
+
input = $stdin
|
61
|
+
end
|
62
|
+
|
63
|
+
collector = lambda{|line|
|
64
|
+
output_lines ? output_lines << line : puts(line)
|
65
|
+
}
|
66
|
+
|
45
67
|
if reduce
|
46
68
|
results = []
|
47
|
-
Pru.map(
|
48
|
-
|
69
|
+
Pru.map(input, map){|out| results << out }
|
70
|
+
collector.call Pru.reduce(results, reduce)
|
49
71
|
else
|
50
|
-
Pru.map(
|
72
|
+
Pru.map(input, map){|out| collector.call out }
|
73
|
+
end
|
74
|
+
|
75
|
+
if options[:file]
|
76
|
+
File.open(options[:file], 'w'){|f| f.write output_lines.join(newline) }
|
51
77
|
end
|
data/pru.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pru}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-27}
|
13
13
|
s.default_executable = %q{pru}
|
14
14
|
s.email = %q{michael@grosser.it}
|
15
15
|
s.executables = ["pru"]
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
]
|
32
32
|
s.homepage = %q{http://github.com/grosser/pru}
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.
|
34
|
+
s.rubygems_version = %q{1.6.2}
|
35
35
|
s.summary = %q{Pipeable Ruby - forget about grep / sed / awk / wc ... use pure, readable Ruby!}
|
36
36
|
s.test_files = [
|
37
37
|
"spec/a_test.rb",
|
data/spec/pru_spec.rb
CHANGED
@@ -5,6 +5,10 @@ describe Pru do
|
|
5
5
|
Pru::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
6
6
|
end
|
7
7
|
|
8
|
+
it "shows help when no arguments are given" do
|
9
|
+
`./bin/pru`.should include('Usage:')
|
10
|
+
end
|
11
|
+
|
8
12
|
describe 'map' do
|
9
13
|
it "selects" do
|
10
14
|
`ls -l | ./bin/pru 'include?("G")'`.split("\n").size.should == 2
|
@@ -84,4 +88,32 @@ describe Pru do
|
|
84
88
|
`echo 1 | ./bin/pru --require jeweler,rake --reduce 'Rake.to_s + Jeweler.to_s'`.should == "RakeJeweler\n"
|
85
89
|
end
|
86
90
|
end
|
91
|
+
|
92
|
+
describe '--inplace-edit FILE' do
|
93
|
+
after do
|
94
|
+
`rm -f xxx`
|
95
|
+
end
|
96
|
+
|
97
|
+
it "modifies the file" do
|
98
|
+
File.open('xxx','w'){|f| f.write "abc\nab\na" }
|
99
|
+
`./bin/pru --inplace-edit xxx size`.should == ''
|
100
|
+
File.read('xxx').should == "3\n2\n1"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "fails with empty file" do
|
104
|
+
`./bin/pru --inplace-edit xxx size 2>&1`.should include('No such file or directory - xxx')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "keeps line separators when modifying" do
|
108
|
+
File.open('xxx','w'){|f| f.write "abc\r\nab\r\na" }
|
109
|
+
`./bin/pru --inplace-edit xxx size`.should == ''
|
110
|
+
File.read('xxx').should == "3\r\n2\r\n1"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "modifies the file with reduce" do
|
114
|
+
File.open('xxx','w'){|f| f.write "abc\nab\na" }
|
115
|
+
`./bin/pru --inplace-edit xxx size inspect`.should == ''
|
116
|
+
File.read('xxx').should == "[3, 2, 1]"
|
117
|
+
end
|
118
|
+
end
|
87
119
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-27 00:00:00 +02:00
|
19
19
|
default_executable: pru
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements: []
|
73
73
|
|
74
74
|
rubyforge_project:
|
75
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.6.2
|
76
76
|
signing_key:
|
77
77
|
specification_version: 3
|
78
78
|
summary: Pipeable Ruby - forget about grep / sed / awk / wc ... use pure, readable Ruby!
|