any_data 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 ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 / 2009-01-01
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/any_data
6
+ lib/any_data.rb
7
+ tasks/autospec.rake
8
+ tasks/bones.rake
9
+ tasks/gem.rake
10
+ tasks/git.rake
11
+ tasks/manifest.rake
12
+ tasks/notes.rake
13
+ tasks/post_load.rake
14
+ tasks/rdoc.rake
15
+ tasks/rubyforge.rake
16
+ tasks/setup.rb
17
+ tasks/test.rake
18
+ test/end_data.rb
19
+ test/helper.rb
20
+ test/runner
21
+ test/spec_any_data.rb
data/README.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = any_data
2
+ by James Tucker
3
+ http://ra66i.org
4
+ http://github.com/raggi/any_data
5
+ http://libraggi.rubyforge.org/any_data
6
+
7
+ == DESCRIPTION:
8
+
9
+ Small helper which provides and IO like ruby's DATA for $0, but for any file.
10
+
11
+ == FEATURES/PROBLEMS:
12
+
13
+ * Are you kidding?
14
+
15
+ == SYNOPSIS:
16
+
17
+ AnyData.new.read
18
+ AnyData.new(other_file).read
19
+
20
+ == REQUIREMENTS:
21
+
22
+ * Ruby
23
+
24
+ == INSTALL:
25
+
26
+ * gem install any_data
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2008 James Tucker
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ load 'tasks/setup.rb'
2
+
3
+ ensure_in_path 'lib'
4
+ require 'any_data'
5
+
6
+ task :default => :test
7
+
8
+ PROJ.name = 'any_data'
9
+ PROJ.authors = 'James Tucker'
10
+ PROJ.email = 'raggi@rubyforge.org'
11
+ PROJ.url = 'http://github.com/raggi/any_data'
12
+ PROJ.rubyforge.name = 'libraggi'
13
+ PROJ.version = AnyData.version
data/bin/any_data ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), '..', 'lib', 'any_data'))
5
+
6
+ # Put your code here
data/lib/any_data.rb ADDED
@@ -0,0 +1,21 @@
1
+ class AnyData < File
2
+ def self.version; '0.1.0'; end
3
+
4
+ class NoDataError < Exception
5
+ attr_accessor :file
6
+ def initialize(file)
7
+ @file = file
8
+ super("No data (__END__) found in file: #{file}")
9
+ end
10
+ end
11
+
12
+ # Open the given file, or the file of the caller, and scans to __END__. This
13
+ # is very similar to the manner in which DATA works for $0. Can raise an
14
+ # AnyData::NoDataError if EOF is reached before finding __END__.
15
+ def initialize(path = (caller.first.split(':').first))
16
+ super(path, 'r')
17
+ line = readline until line =~ /^__END__$/
18
+ rescue EOFError
19
+ raise NoDataError, file
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # Poor mans autotest, for when you absolutely positively, just need an autotest.
2
+ # N.B. Uses a runner under test/ or spec/, so you can customize the runtime.
3
+ # Thanks to manveru for this!
4
+ desc "Run specs every time a file changes in lib or spec"
5
+ task :autospec do
6
+ rb = Gem.ruby rescue nil
7
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
8
+ command = 'spec/runner' if test ?e, 'spec/runner'
9
+ command ||= 'test/runner' if test ?e, 'test/runner'
10
+ files = Dir.glob('{lib,spec,test}/**/*.rb')
11
+ mtimes = {}
12
+ sigtrap = proc { puts "\rDo that again, I dare you!"; trap(:INT){ exit 0 }; sleep 0.8; trap(:INT, &sigtrap) }
13
+ trap(:INT, &sigtrap)
14
+ system "#{rb} -I#{GSpec.require_path} #{command}"
15
+ while file = files.shift
16
+ begin
17
+ mtime = File.mtime(file)
18
+ mtimes[file] ||= mtime
19
+ if mtime > mtimes[file]
20
+ files = Dir.glob('{lib,spec,test}/**/*.rb') - [file] # refresh the file list.
21
+ puts
22
+ system "#{rb} -I#{GSpec.require_path} #{command} #{file}"
23
+ puts
24
+ end
25
+ mtimes[file] = mtime
26
+ files << file
27
+ rescue Exception
28
+ retry
29
+ end
30
+ # print "\rChecking: #{file.ljust((ENV['COLUMNS']||80)-11)}";$stdout.flush
31
+ sleep 0.2
32
+ end
33
+ end
data/tasks/bones.rake ADDED
@@ -0,0 +1,21 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ namespace :bones do
6
+
7
+ desc 'Show the PROJ open struct'
8
+ task :debug do |t|
9
+ atr = if t.application.top_level_tasks.length == 2
10
+ t.application.top_level_tasks.pop
11
+ end
12
+
13
+ if atr then Bones::Debug.show_attr(PROJ, atr)
14
+ else Bones::Debug.show PROJ end
15
+ end
16
+
17
+ end # namespace :bones
18
+
19
+ end # HAVE_BONES
20
+
21
+ # EOF
data/tasks/gem.rake ADDED
@@ -0,0 +1,138 @@
1
+ # $Id$
2
+
3
+ require 'rake/gempackagetask'
4
+
5
+ namespace :gem do
6
+
7
+ PROJ.gem._spec = Gem::Specification.new do |s|
8
+ s.name = PROJ.name
9
+ s.version = PROJ.version
10
+ s.summary = PROJ.summary
11
+ s.authors = Array(PROJ.authors)
12
+ s.email = PROJ.email
13
+ s.homepage = Array(PROJ.url).first
14
+ s.rubyforge_project = PROJ.rubyforge.name
15
+
16
+ s.description = PROJ.description
17
+
18
+ PROJ.gem.dependencies.each do |dep|
19
+ s.add_dependency(*dep)
20
+ end
21
+ PROJ.gem.development_dependencies.each do |dep|
22
+ s.add_development_dependency(*dep)
23
+ end
24
+
25
+ s.files = PROJ.gem.files
26
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
27
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
28
+
29
+ s.bindir = 'bin'
30
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
31
+ s.require_paths = dirs unless dirs.empty?
32
+
33
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
34
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
35
+ excl = Regexp.new(excl.join('|'))
36
+ rdoc_files = PROJ.gem.files.find_all do |fn|
37
+ case fn
38
+ when excl; false
39
+ when incl; true
40
+ else false end
41
+ end
42
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
43
+ s.extra_rdoc_files = rdoc_files
44
+ s.has_rdoc = true
45
+
46
+ if test ?f, PROJ.test.file
47
+ s.test_file = PROJ.test.file
48
+ else
49
+ s.test_files = PROJ.test.files.to_a
50
+ end
51
+
52
+ # Do any extra stuff the user wants
53
+ PROJ.gem.extras.each do |msg, val|
54
+ case val
55
+ when Proc
56
+ val.call(s.send(msg))
57
+ else
58
+ s.send "#{msg}=", val
59
+ end
60
+ end
61
+ end # Gem::Specification.new
62
+
63
+ # A prerequisites task that all other tasks depend upon
64
+ task :prereqs
65
+
66
+ desc 'Show information about the gem'
67
+ task :debug => 'gem:prereqs' do
68
+ puts PROJ.gem._spec.to_ruby
69
+ end
70
+
71
+ pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
72
+ pkg.need_tar = PROJ.gem.need_tar
73
+ pkg.need_zip = PROJ.gem.need_zip
74
+ pkg.package_files += PROJ.gem._spec.files
75
+ end
76
+ Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
77
+
78
+ gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
79
+ "#{pkg.package_name}.gem"
80
+ else
81
+ "#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
82
+ end
83
+
84
+ desc "Build the gem file #{gem_file}"
85
+ task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
86
+
87
+ file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
88
+ when_writing("Creating GEM") {
89
+ Gem::Builder.new(PROJ.gem._spec).build
90
+ verbose(true) {
91
+ mv gem_file, "#{pkg.package_dir}/#{gem_file}"
92
+ }
93
+ }
94
+ end
95
+
96
+ desc 'Install the gem'
97
+ task :install => [:clobber, 'gem:package'] do
98
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
99
+
100
+ # use this version of the command for rubygems > 1.0.0
101
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
102
+ end
103
+
104
+ desc 'Uninstall the gem'
105
+ task :uninstall do
106
+ installed_list = Gem.source_index.find_name(PROJ.name)
107
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
108
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
109
+ end
110
+ end
111
+
112
+ desc 'Reinstall the gem'
113
+ task :reinstall => [:uninstall, :install]
114
+
115
+ desc 'Cleanup the gem'
116
+ task :cleanup do
117
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
118
+ end
119
+
120
+ file "#{PROJ.name}.gemspec" => PROJ.gem._spec.files do |t|
121
+ open(t.name, 'w') { |f| f.write PROJ.gem._spec.to_ruby }
122
+ end
123
+ CLOBBER.include("#{PROJ.name}.gemspec")
124
+
125
+ desc 'Generate gemspec'
126
+ task :spec => "#{PROJ.name}.gemspec"
127
+ task :release => :spec
128
+
129
+ end # namespace :gem
130
+
131
+ desc 'Alias to gem:package'
132
+ task :gem => 'gem:package'
133
+
134
+ task :clobber => 'gem:clobber_package'
135
+
136
+ remove_desc_for_task %w(gem:clobber_package)
137
+
138
+ # EOF
data/tasks/git.rake ADDED
@@ -0,0 +1,41 @@
1
+ # $Id$
2
+
3
+ if HAVE_GIT
4
+
5
+ namespace :git do
6
+
7
+ # A prerequisites task that all other tasks depend upon
8
+ task :prereqs
9
+
10
+ desc 'Show tags from the Git repository'
11
+ task :show_tags => 'git:prereqs' do |t|
12
+ puts %x/git tag/
13
+ end
14
+
15
+ desc 'Create a new tag in the Git repository'
16
+ task :create_tag => 'git:prereqs' do |t|
17
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
18
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
19
+
20
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
21
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
22
+
23
+ puts "Creating Git tag '#{tag}'"
24
+ unless system "git tag -a -m '#{msg}' #{tag}"
25
+ abort "Tag creation failed"
26
+ end
27
+
28
+ if %x/git remote/ =~ %r/^origin\s*$/
29
+ unless system "git push origin #{tag}"
30
+ abort "Could not push tag to remote Git repository"
31
+ end
32
+ end
33
+ end
34
+
35
+ end # namespace :git
36
+
37
+ task 'gem:release' => 'git:create_tag'
38
+
39
+ end # if HAVE_GIT
40
+
41
+ # EOF
@@ -0,0 +1,49 @@
1
+ # $Id$
2
+
3
+ require 'find'
4
+
5
+ namespace :manifest do
6
+
7
+ desc 'Verify the manifest'
8
+ task :check do
9
+ fn = PROJ.manifest_file + '.tmp'
10
+ files = manifest_files
11
+
12
+ File.open(fn, 'w') {|fp| fp.puts files}
13
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
14
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
15
+ lines.map! do |line|
16
+ case line
17
+ when %r/^(-{3}|\+{3})/; nil
18
+ when %r/^@/; Console::ANSICode.blue line
19
+ when %r/^\+/; Console::ANSICode.green line
20
+ when %r/^\-/; Console::ANSICode.red line
21
+ else line end
22
+ end
23
+ end
24
+ puts lines.compact
25
+ rm fn rescue nil
26
+ end
27
+
28
+ desc 'Create a new manifest'
29
+ task :create do
30
+ files = manifest_files
31
+ unless test(?f, PROJ.manifest_file)
32
+ files << PROJ.manifest_file
33
+ files.sort!
34
+ end
35
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
36
+ end
37
+
38
+ task :assert do
39
+ files = manifest_files
40
+ manifest = File.read(PROJ.manifest_file).split($/)
41
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
42
+ end
43
+
44
+ end # namespace :manifest
45
+
46
+ desc 'Alias to manifest:check'
47
+ task :manifest => 'manifest:check'
48
+
49
+ # EOF
data/tasks/notes.rake ADDED
@@ -0,0 +1,28 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ desc "Enumerate all annotations"
6
+ task :notes do |t|
7
+ id = if t.application.top_level_tasks.length > 1
8
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
9
+ end
10
+ Bones::AnnotationExtractor.enumerate(
11
+ PROJ, PROJ.notes.tags.join('|'), id, :tag => true)
12
+ end
13
+
14
+ namespace :notes do
15
+ PROJ.notes.tags.each do |tag|
16
+ desc "Enumerate all #{tag} annotations"
17
+ task tag.downcase.to_sym do |t|
18
+ id = if t.application.top_level_tasks.length > 1
19
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
20
+ end
21
+ Bones::AnnotationExtractor.enumerate(PROJ, tag, id)
22
+ end
23
+ end
24
+ end
25
+
26
+ end # if HAVE_BONES
27
+
28
+ # EOF
@@ -0,0 +1,38 @@
1
+ # $Id$
2
+
3
+ # This file does not define any rake tasks. It is used to load some project
4
+ # settings if they are not defined by the user.
5
+
6
+ PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
7
+ PROJ.exclude << ["^#{Regexp.escape(PROJ.rdoc.dir)}/",
8
+ "^#{Regexp.escape(PROJ.rcov.dir)}/"]
9
+
10
+ flatten_arrays = lambda do |this,os|
11
+ os.instance_variable_get(:@table).each do |key,val|
12
+ next if key == :dependencies
13
+ case val
14
+ when Array; val.flatten!
15
+ when OpenStruct; this.call(this,val)
16
+ end
17
+ end
18
+ end
19
+ flatten_arrays.call(flatten_arrays,PROJ)
20
+
21
+ PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
22
+
23
+ PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
24
+
25
+ PROJ.summary ||= PROJ.description.split('.').first
26
+
27
+ PROJ.gem.files ||=
28
+ if test(?f, PROJ.manifest_file)
29
+ files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
30
+ files.delete ''
31
+ files
32
+ else [] end
33
+
34
+ PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
35
+
36
+ PROJ.rdoc.main ||= PROJ.readme_file
37
+
38
+ # EOF
data/tasks/rdoc.rake ADDED
@@ -0,0 +1,55 @@
1
+ # $Id$
2
+
3
+ begin
4
+ require 'hanna/rdoctask'
5
+ rescue LoadError
6
+ require 'rake/rdoctask'
7
+ end
8
+
9
+ namespace :doc do
10
+
11
+ desc 'Generate RDoc documentation'
12
+ Rake::RDocTask.new do |rd|
13
+ rdoc = PROJ.rdoc
14
+ rd.main = rdoc.main
15
+ rd.rdoc_dir = rdoc.dir
16
+
17
+ incl = Regexp.new(rdoc.include.join('|'))
18
+ excl = Regexp.new(rdoc.exclude.join('|'))
19
+ files = PROJ.gem.files.find_all do |fn|
20
+ case fn
21
+ when excl; false
22
+ when incl; true
23
+ else false end
24
+ end
25
+ rd.rdoc_files.push(*files)
26
+
27
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
28
+
29
+ rf_name = PROJ.rubyforge.name
30
+ title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
31
+
32
+ rd.options << "-t #{title}"
33
+ rd.options.concat(rdoc.opts)
34
+ end
35
+
36
+ desc 'Generate ri locally for testing'
37
+ task :ri => :clobber_ri do
38
+ sh "#{RDOC} --ri -o ri ."
39
+ end
40
+
41
+ task :clobber_ri do
42
+ rm_r 'ri' rescue nil
43
+ end
44
+
45
+ end # namespace :doc
46
+
47
+ desc 'Alias to doc:rdoc'
48
+ task :doc => 'doc:rdoc'
49
+
50
+ desc 'Remove all build products'
51
+ task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
52
+
53
+ remove_desc_for_task %w(doc:clobber_rdoc)
54
+
55
+ # EOF
@@ -0,0 +1,57 @@
1
+
2
+ if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
3
+
4
+ require 'rubyforge'
5
+ require 'rake/contrib/sshpublisher'
6
+
7
+ namespace :gem do
8
+ desc 'Package and upload to RubyForge'
9
+ task :release => [:clobber, 'gem:package'] do |t|
10
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
+ pkg = "pkg/#{PROJ.gem._spec.full_name}"
13
+
14
+ if $DEBUG then
15
+ puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
16
+ puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
17
+ end
18
+
19
+ rf = RubyForge.new
20
+ rf.configure rescue nil
21
+ puts 'Logging in'
22
+ rf.login
23
+
24
+ c = rf.userconfig
25
+ c['release_notes'] = PROJ.description if PROJ.description
26
+ c['release_changes'] = PROJ.changes if PROJ.changes
27
+ c['preformatted'] = true
28
+
29
+ files = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
+ (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
+ "#{pkg}.gem"].compact
32
+
33
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
+ rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
35
+ end
36
+ end # namespace :gem
37
+
38
+
39
+ namespace :doc do
40
+ desc "Publish RDoc to RubyForge"
41
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
+ config = YAML.load(
43
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
+ )
45
+
46
+ host = "#{config['username']}@rubyforge.org"
47
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
48
+ remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
49
+ local_dir = PROJ.rdoc.dir
50
+
51
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
+ end
53
+ end # namespace :doc
54
+
55
+ end # if HAVE_RUBYFORGE
56
+
57
+ # EOF
data/tasks/setup.rb ADDED
@@ -0,0 +1,238 @@
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ class OpenStruct; undef :gem; end
10
+
11
+ PROJ = OpenStruct.new(
12
+ # Project Defaults
13
+ :name => nil,
14
+ :summary => nil,
15
+ :description => nil,
16
+ :changes => nil,
17
+ :authors => nil,
18
+ :email => nil,
19
+ :url => "\000",
20
+ :version => ENV['VERSION'] || '0.0.0',
21
+ :exclude => %w(tmp$ bak$ ~$ CVS \.git/ \.hg/ \.svn/ ^pkg/ ^doc/ \.DS_Store
22
+ \.hgignore \.gitignore \.dotest \.swp$),
23
+ :release_name => ENV['RELEASE'],
24
+
25
+ # System Defaults
26
+ :ruby_opts => %w(-w),
27
+ :libs => [],
28
+ :history_file => 'History.txt',
29
+ :manifest_file => 'Manifest.txt',
30
+ :readme_file => 'README.rdoc',
31
+
32
+ # Gem Packaging
33
+ :gem => OpenStruct.new(
34
+ :dependencies => [],
35
+ :development_dependencies => ['rake', 'bones', 'bacon'],
36
+ :executables => nil,
37
+ :extensions => FileList['ext/**/extconf.rb'],
38
+ :files => nil,
39
+ :need_tar => true,
40
+ :need_zip => false,
41
+ :extras => {}
42
+ ),
43
+
44
+ # File Annotations
45
+ :notes => OpenStruct.new(
46
+ :exclude => %w(^tasks/setup\.rb$),
47
+ :extensions => %w(.txt .rb .erb .rdoc) << '',
48
+ :tags => %w(FIXME OPTIMIZE TODO)
49
+ ),
50
+
51
+ # Rcov
52
+ :rcov => OpenStruct.new(
53
+ :dir => 'coverage',
54
+ :opts => %w[--sort coverage -T],
55
+ :threshold => 90.0,
56
+ :threshold_exact => false
57
+ ),
58
+
59
+ # Rdoc
60
+ :rdoc => OpenStruct.new(
61
+ :opts => [],
62
+ :include => %w(^lib/ ^bin/ ^ext/ \.txt$),
63
+ :exclude => %w(extconf\.rb$),
64
+ :main => nil,
65
+ :dir => 'doc',
66
+ :remote_dir => nil
67
+ ),
68
+
69
+ # Rubyforge
70
+ :rubyforge => OpenStruct.new(
71
+ :name => "\000"
72
+ ),
73
+
74
+ # Tests
75
+ :test => OpenStruct.new(
76
+ :files => FileList['{test,spec}/{{test,spec}_*.rb,*_spec.rb}'],
77
+ :file => '',
78
+ :opts => []
79
+ )
80
+ )
81
+
82
+ # Load the other rake files in the tasks folder
83
+ rakefiles = Dir.glob('tasks/*.rake').sort
84
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
85
+ import(*rakefiles)
86
+
87
+ # Setup the project libraries
88
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
89
+
90
+ # Setup some constants
91
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
92
+
93
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
94
+
95
+ def quiet( &block )
96
+ io = [STDOUT.dup, STDERR.dup]
97
+ STDOUT.reopen DEV_NULL
98
+ STDERR.reopen DEV_NULL
99
+ block.call
100
+ ensure
101
+ STDOUT.reopen io.first
102
+ STDERR.reopen io.last
103
+ $stdout, $stderr = STDOUT, STDERR
104
+ end
105
+
106
+ DIFF = if WIN32 then 'diff.exe'
107
+ else
108
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
109
+ else 'diff' end
110
+ end unless defined? DIFF
111
+
112
+ SUDO = if WIN32 then ''
113
+ else
114
+ if quiet {system 'which sudo'} then 'sudo'
115
+ else '' end
116
+ end
117
+
118
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
119
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
120
+ GEM = WIN32 ? 'gem.bat' : 'gem'
121
+
122
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
123
+ begin
124
+ require lib
125
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
126
+ rescue LoadError
127
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
128
+ end
129
+ end
130
+ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
131
+ system("svn --version 2>&1 > #{DEV_NULL}"))
132
+ HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
133
+ system("git --version 2>&1 > #{DEV_NULL}"))
134
+
135
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
136
+ # specified.
137
+ #
138
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
139
+ # summary, *description = paragraphs_of('README.rdoc', 3, 3..8)
140
+ #
141
+ def paragraphs_of( path, *paragraphs )
142
+ title = String === paragraphs.first ? paragraphs.shift : nil
143
+ ary = File.read(path).delete("\r").split(/\n\n+/)
144
+
145
+ result = if title
146
+ tmp, matching = [], false
147
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
148
+ paragraphs << (0..-1) if paragraphs.empty?
149
+
150
+ ary.each do |val|
151
+ if val =~ rgxp
152
+ break if matching
153
+ matching = true
154
+ rgxp = %r/^=+/i
155
+ elsif matching
156
+ tmp << val
157
+ end
158
+ end
159
+ tmp
160
+ else ary end
161
+
162
+ result.values_at(*paragraphs)
163
+ end
164
+
165
+ # Adds the given gem _name_ to the current project's dependency list. An
166
+ # optional gem _version_ can be given. If omitted, the newest gem version
167
+ # will be used.
168
+ #
169
+ def depend_on( name, version = nil )
170
+ spec = Gem.source_index.find_name(name).last
171
+ version = spec.version.to_s if version.nil? and !spec.nil?
172
+
173
+ PROJ.gem.dependencies << case version
174
+ when nil; [name]
175
+ when %r/^\d/; [name, ">= #{version}"]
176
+ else [name, version] end
177
+ end
178
+
179
+ # Adds the given arguments to the include path if they are not already there
180
+ #
181
+ def ensure_in_path( *args )
182
+ args.each do |path|
183
+ path = File.expand_path(path)
184
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
185
+ end
186
+ end
187
+
188
+ # Find a rake task using the task name and remove any description text. This
189
+ # will prevent the task from being displayed in the list of available tasks.
190
+ #
191
+ def remove_desc_for_task( names )
192
+ Array(names).each do |task_name|
193
+ task = Rake.application.tasks.find {|t| t.name == task_name}
194
+ next if task.nil?
195
+ task.instance_variable_set :@comment, nil
196
+ end
197
+ end
198
+
199
+ # Change working directories to _dir_, call the _block_ of code, and then
200
+ # change back to the original working directory (the current directory when
201
+ # this method was called).
202
+ #
203
+ def in_directory( dir, &block )
204
+ curdir = pwd
205
+ begin
206
+ cd dir
207
+ return block.call
208
+ ensure
209
+ cd curdir
210
+ end
211
+ end
212
+
213
+ # Scans the current working directory and creates a list of files that are
214
+ # candidates to be in the manifest.
215
+ #
216
+ def manifest_files
217
+ files = []
218
+ exclude = Regexp.new(PROJ.exclude.join('|'))
219
+ Find.find '.' do |path|
220
+ path.sub! %r/^(\.\/|\/)/o, ''
221
+ next unless test ?f, path
222
+ next if path =~ exclude
223
+ files << path
224
+ end
225
+ files.sort!
226
+ end
227
+
228
+ # We need a "valid" method thtat determines if a string is suitable for use
229
+ # in the gem specification.
230
+ #
231
+ class Object
232
+ def valid?
233
+ return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
234
+ return false
235
+ end
236
+ end
237
+
238
+ # EOF
data/tasks/test.rake ADDED
@@ -0,0 +1,39 @@
1
+ # $Id$
2
+
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
10
+ else PROJ.test.files end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test.opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
21
+ else PROJ.test.files end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+ task :spec => :test
36
+
37
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
38
+
39
+ # EOF
data/test/end_data.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ test = 1,2,3
3
+
4
+ __END__
5
+ 10,11,12
6
+ 13,14,15
data/test/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ # Disable test/unit and rspec from running, in case loaded by broken tools.
2
+ Test::Unit.run = false if defined?(Test) && defined?(Test::Unit)
3
+ Spec::run = false if defined?(Spec) && Spec::respond_to?(:run=)
4
+
5
+ # Setup a nice testing environment
6
+ $DEBUG, $TESTING = true, true
7
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $:.uniq!
9
+
10
+ %w[rubygems bacon].each { |r| require r }
11
+
12
+ # Bacon doesn't do any automagic, so lets tell it to!
13
+ Bacon.summary_on_exit
14
+
15
+ require File.expand_path(
16
+ File.join(File.dirname(__FILE__), %w[.. lib any_data]))
data/test/runner ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ __DIR__ = File.dirname(__FILE__)
3
+ __APP__ = File.expand_path(__DIR__ + '/../')
4
+
5
+ puts
6
+ Dir.chdir(__APP__) do
7
+ files = ARGV.empty? ? Dir.glob('{test,spec}/**/{test,spec}_*.rb') : ARGV
8
+ files.each { |f| require f }
9
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ describe 'AnyData' do
4
+
5
+ should "read from the calling file after __END__" do
6
+ AnyData.new.read.should.eql("1,2,3\n4,5,6\n7,8,9")
7
+ end
8
+
9
+ should "read from the given file after __END__" do
10
+ file = File.expand_path File.join(File.dirname(__FILE__), 'end_data.rb')
11
+ AnyData.new(file).read.should.eql("10,11,12\n13,14,15")
12
+ end
13
+
14
+ end
15
+
16
+ __END__
17
+ 1,2,3
18
+ 4,5,6
19
+ 7,8,9
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: any_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Tucker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-01 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: bones
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bacon
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Small helper which provides and IO like ruby's DATA for $0, but for any file.
46
+ email: raggi@rubyforge.org
47
+ executables:
48
+ - any_data
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History.txt
53
+ - bin/any_data
54
+ files:
55
+ - History.txt
56
+ - Manifest.txt
57
+ - README.rdoc
58
+ - Rakefile
59
+ - bin/any_data
60
+ - lib/any_data.rb
61
+ - tasks/autospec.rake
62
+ - tasks/bones.rake
63
+ - tasks/gem.rake
64
+ - tasks/git.rake
65
+ - tasks/manifest.rake
66
+ - tasks/notes.rake
67
+ - tasks/post_load.rake
68
+ - tasks/rdoc.rake
69
+ - tasks/rubyforge.rake
70
+ - tasks/setup.rb
71
+ - tasks/test.rake
72
+ - test/end_data.rb
73
+ - test/helper.rb
74
+ - test/runner
75
+ - test/spec_any_data.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/raggi/any_data
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --main
81
+ - README.rdoc
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: libraggi
99
+ rubygems_version: 1.3.1
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: Small helper which provides and IO like ruby's DATA for $0, but for any file
103
+ test_files:
104
+ - test/spec_any_data.rb