chirp 0.1.0
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/History.txt +5 -0
- data/Manifest.txt +7 -0
- data/README.txt +48 -0
- data/Rakefile +17 -0
- data/bin/chirp +0 -0
- data/lib/chirp.rb +232 -0
- data/test/test_chirp.rb +0 -0
- metadata +60 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
chirp
|
2
|
+
by FIX (your name)
|
3
|
+
FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2007 FIX
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/chirp.rb'
|
6
|
+
|
7
|
+
Hoe.new('chirp', Chirp::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'chirp'
|
9
|
+
# p.author = 'FIX'
|
10
|
+
# p.email = 'FIX'
|
11
|
+
# p.summary = 'FIX'
|
12
|
+
# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
# vim: syntax=Ruby
|
data/bin/chirp
ADDED
File without changes
|
data/lib/chirp.rb
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright 2006 Russell Olsen
|
4
|
+
# Chirp is distributed under the same license as Ruby itself.
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'pathname'
|
8
|
+
require 'pp'
|
9
|
+
require 'ftools'
|
10
|
+
require 'tempfile'
|
11
|
+
require 'forwardable'
|
12
|
+
|
13
|
+
module Chirp
|
14
|
+
|
15
|
+
VERSION = '0.1.0'
|
16
|
+
|
17
|
+
def Chirp.application
|
18
|
+
@application ||= Chirp::Application.new
|
19
|
+
end
|
20
|
+
|
21
|
+
class PatternAction
|
22
|
+
attr_reader :block
|
23
|
+
|
24
|
+
def initialize(re, block)
|
25
|
+
@re = re
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def matches(file, line, line_no)
|
30
|
+
@re =~ line
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class LineNumberAction
|
35
|
+
attr_reader :block
|
36
|
+
|
37
|
+
def initialize(number, block)
|
38
|
+
@number = number
|
39
|
+
@block = block
|
40
|
+
end
|
41
|
+
|
42
|
+
def matches(file, line, line_no)
|
43
|
+
line_no == @number
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def Chirp.field_separator=(value)
|
49
|
+
application.field_separator=value
|
50
|
+
end
|
51
|
+
|
52
|
+
def Chirp.field_separator
|
53
|
+
application.field_separator
|
54
|
+
end
|
55
|
+
|
56
|
+
def Chirp.line
|
57
|
+
application.line
|
58
|
+
end
|
59
|
+
|
60
|
+
def Chirp.fields
|
61
|
+
application.fields
|
62
|
+
end
|
63
|
+
|
64
|
+
def Chirp.line_no
|
65
|
+
application.line_no
|
66
|
+
end
|
67
|
+
|
68
|
+
def Chirp.file
|
69
|
+
application.file
|
70
|
+
end
|
71
|
+
|
72
|
+
def Chirp.edit_in_place=(value)
|
73
|
+
application.edit_in_place = value
|
74
|
+
end
|
75
|
+
|
76
|
+
def Chirp.files=(value)
|
77
|
+
application.files=value
|
78
|
+
end
|
79
|
+
|
80
|
+
def Chirp.pattern( re, &block )
|
81
|
+
application.pattern(re, block)
|
82
|
+
end
|
83
|
+
|
84
|
+
def Chirp.line_number( n, &block )
|
85
|
+
application.line_number(n, block)
|
86
|
+
end
|
87
|
+
|
88
|
+
def Chirp.before &block
|
89
|
+
application.before(block)
|
90
|
+
end
|
91
|
+
|
92
|
+
def Chirp.before_file &block
|
93
|
+
application.before_file(block)
|
94
|
+
end
|
95
|
+
|
96
|
+
def Chirp.after_file &block
|
97
|
+
application.after_file(block)
|
98
|
+
end
|
99
|
+
|
100
|
+
def Chirp.after &block
|
101
|
+
application.after(block)
|
102
|
+
end
|
103
|
+
|
104
|
+
class Application
|
105
|
+
|
106
|
+
attr_accessor :field_separator
|
107
|
+
attr_reader :fields, :line, :line_no, :file
|
108
|
+
|
109
|
+
def initialize
|
110
|
+
@before_actions=[]
|
111
|
+
@before_file_actions=[]
|
112
|
+
@pattern_actions=[]
|
113
|
+
@after_file_actions=[]
|
114
|
+
@after_actions=[]
|
115
|
+
end
|
116
|
+
|
117
|
+
def files=(glob)
|
118
|
+
if glob.respond_to? :[]
|
119
|
+
@glob=glob
|
120
|
+
else
|
121
|
+
@glob = [ glob ]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def edit_in_place=(value)
|
126
|
+
@edit_in_place=value
|
127
|
+
end
|
128
|
+
|
129
|
+
def has_run?
|
130
|
+
@has_run
|
131
|
+
end
|
132
|
+
|
133
|
+
def run
|
134
|
+
@has_run = true
|
135
|
+
@before_actions.each do |action|
|
136
|
+
action.call
|
137
|
+
end
|
138
|
+
|
139
|
+
if not @glob
|
140
|
+
process_stream
|
141
|
+
elsif @edit_in_place
|
142
|
+
process_edits(@glob)
|
143
|
+
else
|
144
|
+
process_streams(@glob)
|
145
|
+
end
|
146
|
+
|
147
|
+
@after_actions.each do |action|
|
148
|
+
action.call
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
def process_edits(glob)
|
154
|
+
glob.each do |path_pattern|
|
155
|
+
Dir.glob(path_pattern) do |path|
|
156
|
+
puts path
|
157
|
+
next if not Pathname.new(path).file?
|
158
|
+
backup_path = path + ".bak"
|
159
|
+
File.copy(path, backup_path)
|
160
|
+
open(backup_path,"r") do |in_stream|
|
161
|
+
open(path, "w") { |out_stream| process_stream(in_stream, out_stream, path) }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def process_streams(glob)
|
168
|
+
glob.each do |path_pattern|
|
169
|
+
Dir.glob(path_pattern) do |path|
|
170
|
+
open(path,"r") { |stream| process_stream(stream, STDOUT, path) }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def process_stream(in_stream=STDIN, out_stream=STDOUT, name='')
|
176
|
+
@file=name
|
177
|
+
old_stdout, $stdout = $stdout, out_stream
|
178
|
+
run_before_file_actions(name)
|
179
|
+
@line_no = 1
|
180
|
+
while not in_stream.eof?
|
181
|
+
@line = in_stream.readline.chomp
|
182
|
+
@fields=line.split(@field_separator)
|
183
|
+
@pattern_actions.each do |pa|
|
184
|
+
if pa.matches(name, @line, @line_no)
|
185
|
+
Chirp.module_eval &pa.block
|
186
|
+
end
|
187
|
+
end
|
188
|
+
@line_no += 1
|
189
|
+
end
|
190
|
+
run_after_file_actions(name)
|
191
|
+
$stdout = old_stdout
|
192
|
+
end
|
193
|
+
|
194
|
+
def run_before_file_actions(name)
|
195
|
+
@before_file_actions.each { |a| a.call(name) }
|
196
|
+
end
|
197
|
+
|
198
|
+
def run_after_file_actions(name)
|
199
|
+
@after_file_actions.each { |a| a.call(name) }
|
200
|
+
end
|
201
|
+
|
202
|
+
def pattern(re, block)
|
203
|
+
@pattern_actions << PatternAction.new(re, block)
|
204
|
+
end
|
205
|
+
|
206
|
+
def line_number(n, block)
|
207
|
+
@pattern_actions << LineNumberAction.new(n, block)
|
208
|
+
end
|
209
|
+
|
210
|
+
def before(block)
|
211
|
+
@before_actions << block
|
212
|
+
end
|
213
|
+
|
214
|
+
def before_file(block)
|
215
|
+
@before_file_actions << block
|
216
|
+
end
|
217
|
+
|
218
|
+
def after_file(block)
|
219
|
+
@after_file_actions << block
|
220
|
+
end
|
221
|
+
|
222
|
+
def after(block)
|
223
|
+
@after_actions << block
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
at_exit do
|
229
|
+
Chirp::application.run if not Chirp::application.has_run?
|
230
|
+
end
|
231
|
+
|
232
|
+
|
data/test/test_chirp.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: chirp
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-11-09
|
8
|
+
summary: The author was too lazy to write a summary
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ryand-ruby@zenspider.com
|
12
|
+
homepage: http://www.zenspider.com/ZSS/Products/chirp/
|
13
|
+
rubyforge_project: chirp
|
14
|
+
description: The author was too lazy to write a description
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
authors:
|
27
|
+
- Ryan Davis
|
28
|
+
files:
|
29
|
+
- History.txt
|
30
|
+
- Manifest.txt
|
31
|
+
- README.txt
|
32
|
+
- Rakefile
|
33
|
+
- bin/chirp
|
34
|
+
- lib/chirp.rb
|
35
|
+
- test/test_chirp.rb
|
36
|
+
test_files:
|
37
|
+
- test/test_chirp.rb
|
38
|
+
rdoc_options:
|
39
|
+
- --main
|
40
|
+
- README.txt
|
41
|
+
extra_rdoc_files:
|
42
|
+
- History.txt
|
43
|
+
- Manifest.txt
|
44
|
+
- README.txt
|
45
|
+
executables:
|
46
|
+
- chirp
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: hoe
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.3.0
|
60
|
+
version:
|