author | Mahlon E. Smith <mahlon@martini.nu> |
Fri, 21 Jan 2011 19:41:16 -0800 | |
branch | ruby-modules |
changeset 4 | 01a3332bfe0a |
parent 3 | 233041485364 |
child 6 | 62a5ac525ce8 |
permissions | -rw-r--r-- |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
1 |
#!/usr/bin/env rake |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
2 |
# |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
3 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
4 |
require 'rubygems' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
5 |
require 'pathname' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
6 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
7 |
require 'rake' |
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
8 |
require 'rspec' |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
9 |
require 'rspec/core/rake_task' |
2 | 10 |
require 'rake/packagetask' |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
11 |
require 'rake/gempackagetask' |
2 | 12 |
require 'rubygems/installer' |
13 |
require 'rubygems/uninstaller' |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
14 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
15 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
16 |
###################################################################### |
2 | 17 |
### P A T H S A N D F I L E S |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
18 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
19 |
|
2 | 20 |
BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd ) |
21 |
||
22 |
TEXT_FILES = %w{ Rakefile README LICENSE }.collect {|f| BASEDIR + f } |
|
23 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
24 |
SPECDIR = BASEDIR + 'spec' |
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
25 |
SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ) |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
26 |
|
2 | 27 |
LIBDIR = BASEDIR + 'lib' |
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
28 |
LIB_FILES = Pathname.glob( LIBDIR + '**/*.rb') |
2 | 29 |
|
30 |
RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES |
|
31 |
||
32 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
33 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
34 |
### H E L P E R S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
35 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
36 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
37 |
### Given a +file+ path, find the first captured match of +pattern+, |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
38 |
### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
39 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
40 |
def find_pattern( file, pattern ) |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
41 |
ver = nil |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
42 |
File.open( file ) do |f| |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
43 |
ver = f.each do |line| |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
44 |
break $1 if line =~ pattern |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
45 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
46 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
47 |
return ver.is_a?( String ) ? ver : 'UNKNOWN' |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
48 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
49 |
|
2 | 50 |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
51 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
52 |
### P A C K A G E C O N S T A N T S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
53 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
54 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
55 |
PKG_NAME = 'chunker' |
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
56 |
PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](.+)['"]/ ) |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
57 |
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
58 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
59 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
60 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
61 |
### T A S K S |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
62 |
###################################################################### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
63 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
64 |
task :test => 'test:spec' |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
65 |
task :default => :test |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
66 |
# task :default => [ :test, :package ] |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
67 |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
68 |
namespace :test do |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
69 |
desc 'Generate verbose and pretty output' |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
70 |
RSpec::Core::RakeTask.new( :spec ) do |task| |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
71 |
task.pattern = SPEC_FILES |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
72 |
task.rspec_opts = ['-b', '-fd', '-c'] |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
73 |
end |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
74 |
|
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
75 |
desc 'Generate quiet non-colored plain-text output' |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
76 |
RSpec::Core::RakeTask.new( :quiet ) do |task| |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
77 |
task.pattern = SPEC_FILES |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
78 |
task.rspec_opts = ['-f', 'p'] |
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
79 |
end |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
80 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
81 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
82 |
### Task: generate ctags |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
83 |
### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway. |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
84 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
85 |
desc "Generate a ctags 'tags' file from Chunker source" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
86 |
task :ctags do |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
87 |
sh "ctags -R #{LIBDIR}" |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
88 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
89 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
90 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
91 |
### Task: Create gem from source |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
92 |
### |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
93 |
gem = Gem::Specification.new do |gem| |
2 | 94 |
gem.summary = "A convenience library for parsing __END__ tokens consistently." |
95 |
gem.name = PKG_NAME |
|
4
01a3332bfe0a
Bump Chunker to 1.0.0 (release), updates for rspec 2.
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
96 |
gem.version = PKG_VERSION |
2 | 97 |
gem.author = 'Mahlon E. Smith' |
98 |
gem.email = 'mahlon@martini.nu' |
|
3 | 99 |
gem.homepage = 'http://projects.martini.nu/ruby-modules/wiki/Chunker' |
2 | 100 |
gem.has_rdoc = true |
101 |
||
102 |
gem.files = RELEASE_FILES. |
|
103 |
collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
104 |
gem.test_files = SPEC_FILES. |
|
105 |
collect {|f| f.relative_path_from(BASEDIR).to_s } |
|
106 |
||
107 |
gem.description = <<-EOF |
|
108 |
Ruby provides an automatic constant called DATA, which is an IO object |
|
109 |
that references all text in the current file under an __END__ token. |
|
110 |
||
111 |
I find it convenient to use the __END__ area to store all sorts of |
|
112 |
stuff, rather than have to worry about distributing separate files. |
|
113 |
||
114 |
The DATA constant is determined from whatever ruby believes $0 to be. |
|
115 |
It doesn't work inside of other required libraries, so you'll see stuff |
|
116 |
like this all the time: |
|
117 |
||
118 |
END = File.open( __FILE__ ).read.split( /^__END__/, 2 ).last |
|
119 |
||
120 |
It works, but it's more work than I want to do. |
|
121 |
||
122 |
Chunker solves this by parsing __END__ tokens for you, and making it |
|
123 |
available in the form of a 'DATA_END' constant. It installs this |
|
124 |
constant into the class that includes Chunker, so you can use it again |
|
125 |
and again, assuming you use a different file for each class. |
|
126 |
||
127 |
It also automatically parses out other things that look like tokens, so |
|
128 |
you can easily have multiple, distinct documents all embedded into the |
|
129 |
__END__ block. |
|
130 |
EOF |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
131 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
132 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
133 |
Rake::GemPackageTask.new( gem ) do |pkg| |
2 | 134 |
pkg.need_zip = true |
135 |
pkg.need_tar = true |
|
136 |
pkg.need_tar_bz2 = true |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
137 |
end |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
138 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
139 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
140 |
### Task: install |
2 | 141 |
### |
142 |
task :install_gem => [ :package ] do |
|
143 |
$stderr.puts |
|
144 |
installer = Gem::Installer.new( "pkg/#{PKG_FILE_NAME}.gem" ) |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
145 |
installer.install |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
146 |
end |
2 | 147 |
task :install => [ :install_gem ] |
148 |
||
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
149 |
|
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
150 |
### Task: uninstall |
2 | 151 |
### |
152 |
task :uninstall_gem do |
|
153 |
uninstaller = Gem::Uninstaller.new( PKG_NAME ) |
|
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
154 |
uninstaller.uninstall |
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
155 |
end |
2 | 156 |
task :uninstall => [ :uninstall_gem ] |
1
9e127bf6e84f
Initial commit of chunker, a ruby module to aid with data blocks.
mahlon
parents:
diff
changeset
|
157 |