Bump Chunker to 1.0.0 (release), updates for rspec 2.
This commit is contained in:
parent
935090c21b
commit
6667792230
5 changed files with 94 additions and 93 deletions
|
|
@ -1,4 +1,8 @@
|
|||
#!/usr/bin/ruby
|
||||
# vim: set nosta noet ts=4 sw=4:
|
||||
|
||||
require 'strscan'
|
||||
require 'stringio'
|
||||
|
||||
#
|
||||
# Chunker: A convenience library for parsing __END__ tokens consistently.
|
||||
#
|
||||
|
|
@ -17,20 +21,14 @@
|
|||
###
|
||||
module Chunker
|
||||
|
||||
require 'strscan'
|
||||
require 'stringio'
|
||||
# VCS Revision
|
||||
VCSRev = %q$Rev$
|
||||
|
||||
# SVN Revision
|
||||
#
|
||||
SVNRev = %q$Rev$
|
||||
|
||||
# SVN Id
|
||||
#
|
||||
SVNId = %q$Id$
|
||||
# VCS Id
|
||||
VCSId = %q$Id$
|
||||
|
||||
# Package version
|
||||
#
|
||||
VERSION = '0.1'
|
||||
VERSION = '1.0.0'
|
||||
|
||||
|
||||
### Parser class for __END__ data blocks.
|
||||
|
|
@ -40,11 +38,9 @@ module Chunker
|
|||
class DataParser
|
||||
|
||||
# The mark for a DATA block.
|
||||
#
|
||||
END_TOKEN = /^__END__\r?\n/
|
||||
|
||||
# The mark for a 'sub' block.
|
||||
#
|
||||
CHUNK_TOKEN = /^__([A-Z\_0-9]+)__\r?\n/
|
||||
|
||||
|
||||
|
|
@ -59,11 +55,14 @@ module Chunker
|
|||
@scanner = StringScanner.new( end_string )
|
||||
io.close
|
||||
|
||||
# put each chunk into its own constant
|
||||
#
|
||||
if @scanner.check_until( CHUNK_TOKEN )
|
||||
# put each chunk into its own constant
|
||||
self.extract_blocks
|
||||
|
||||
# no sub blocks, put the whole mess into DATA_END
|
||||
#
|
||||
else
|
||||
# no sub blocks, put the whole mess into DATA_END
|
||||
@klass.const_set( :DATA_END, StringIO.new( end_string ) )
|
||||
end
|
||||
end
|
||||
|
|
@ -93,20 +92,20 @@ module Chunker
|
|||
else
|
||||
label = @scanner[1]
|
||||
|
||||
# Pull the next token text out of the data, set up the next pass
|
||||
#
|
||||
if data = @scanner.scan_until( CHUNK_TOKEN )
|
||||
# Pull the next token text out of the data, set up the next pass
|
||||
#
|
||||
data = data[ 0, data.length - @scanner[0].length ]
|
||||
data = data[ 0, data.length - @scanner[0].length ]
|
||||
@scanner.pos = self.next_position
|
||||
|
||||
# No additional blocks
|
||||
#
|
||||
else
|
||||
# No additional blocks
|
||||
#
|
||||
data = @scanner.rest
|
||||
end
|
||||
end
|
||||
|
||||
# Add the IO constant to the class that included me.
|
||||
#
|
||||
@klass.const_set( "DATA_#{label}".to_sym, StringIO.new( data ) )
|
||||
end
|
||||
end
|
||||
|
|
@ -126,7 +125,6 @@ module Chunker
|
|||
def self.included( klass )
|
||||
# klass.instance_eval{ __FILE__ } awww, nope.
|
||||
# __FILE__ won't work here, so we find the filename via caller().
|
||||
#
|
||||
io = File.open( caller(1).last.sub(/:.*?$/, ''), 'r' )
|
||||
|
||||
DataParser.new( klass, io )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue