Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added first package

  • Loading branch information...
commit 7296e072395404b36c532992495224dfce9a6d83 1 parent a01ac0d
Justin Marney authored
View
1  Manifest.txt
@@ -2,7 +2,6 @@ History.txt
Manifest.txt
README.txt
Rakefile
-bin/simple_importer
lib/simple_importer.rb
tasks/ann.rake
tasks/annotations.rake
View
1  Rakefile
@@ -16,5 +16,6 @@ PROJ.url = 'FIXME (project homepage)'
PROJ.rubyforge_name = 'simple_importer'
PROJ.spec_opts << '--color'
+PROJ.version = SimpleImporter::VERSION
# EOF
View
17 lib/simple_importer.rb
@@ -4,6 +4,8 @@
# Used to prevent the class/module from being loaded more than once
unless defined? SimpleImporter
+require 'csv'
+
module SimpleImporter
def file(path)
path = File.join(RAILS_ROOT, 'data', path)
@@ -13,7 +15,16 @@ def file(path)
end
def csv(path)
- require 'csv' unless defined? CSV
+ file(path) do |f|
+ parsed_file = CSV::Reader.parse(f)
+ parsed_file.each do |row|
+ row.each {|v| v.trim! if v.respond_to? :trim! }
+ yield row if block_given?
+ end
+ end
+ end
+
+ def tsv(path)
file(path) do |f|
parsed_file = CSV::Reader.parse(f)
parsed_file.each do |row|
@@ -31,8 +42,8 @@ def xml(path)
end
end
- def run
- reset if respond_to? :reset
+ def run(reset_flag = false)
+ reset if reset_flag && respond_to?(:reset)
import
end
View
BIN  pkg/simple_importer-1.0.0.gem
Binary file not shown
View
BIN  pkg/simple_importer-1.0.0.tgz
Binary file not shown
View
4 pkg/simple_importer-1.0.0/History.txt
@@ -0,0 +1,4 @@
+== 1.0.0 / 2008-06-10
+
+* 1 major enhancement
+ * Birthday!
View
17 pkg/simple_importer-1.0.0/Manifest.txt
@@ -0,0 +1,17 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+lib/simple_importer.rb
+tasks/ann.rake
+tasks/annotations.rake
+tasks/bones.rake
+tasks/doc.rake
+tasks/gem.rake
+tasks/manifest.rake
+tasks/post_load.rake
+tasks/rubyforge.rake
+tasks/setup.rb
+tasks/test.rake
+test/test_helper.rb
+test/test_simple_importer.rb
View
74 pkg/simple_importer-1.0.0/README.txt
@@ -0,0 +1,74 @@
+simple_importer
+ by Justin Marney
+ FIXME (url)
+
+== DESCRIPTION:
+
+Simple API for importing from csv, tsv and xml.
+
+== FEATURES/PROBLEMS:
+
+* FIXME (list of features or problems)
+
+== SYNOPSIS:
+
+# extend your import modules and define import methods
+module XmlImporter
+ extend SimpleImporter
+
+ # if true is passed to run, reset will get called first if it exists.
+ def self.reset
+ Accessory.find(:all).each {|a| a.destroy }
+ end
+
+ def self.import
+ csv('Accessory Schema.csv') do |row|
+ unless row[0].nil? || row[0] == 'SKU'
+ accessory = Accessory.create!(:sku => row[0],
+ :image => row[1],
+ :thumbnail_image => row[2],
+ :name => row[3],
+ :supplier_cost => row[4],
+ :retail_cost => row[5],
+ :description => row[6])
+ end
+ end
+ end
+end
+
+# run your import modules (from a rake task perhaps)
+XmlImporter.run
+
+== REQUIREMENTS:
+
+Hpricot is required if you intend to import xml.
+test/spec and mocha are required to run the tests.
+
+== INSTALL:
+
+* FIXME (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 Justin Marney
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
21 pkg/simple_importer-1.0.0/Rakefile
@@ -0,0 +1,21 @@
+# Look in the tasks/setup.rb file for the various options that can be
+# configured in this Rakefile. The .rake files in the tasks directory
+# are where the options are used.
+
+load 'tasks/setup.rb'
+
+ensure_in_path 'lib'
+require 'simple_importer'
+
+task :default => 'spec:run'
+
+PROJ.name = 'simple_importer'
+PROJ.authors = 'Justin Marney'
+PROJ.email = 'justin.marney@viget.com'
+PROJ.url = 'FIXME (project homepage)'
+PROJ.rubyforge_name = 'simple_importer'
+
+PROJ.spec_opts << '--color'
+PROJ.version = SimpleImporter::VERSION
+
+# EOF
View
97 pkg/simple_importer-1.0.0/lib/simple_importer.rb
@@ -0,0 +1,97 @@
+# $Id$
+
+# Equivalent to a header guard in C/C++
+# Used to prevent the class/module from being loaded more than once
+unless defined? SimpleImporter
+
+require 'csv'
+
+module SimpleImporter
+ def file(path)
+ path = File.join(RAILS_ROOT, 'data', path)
+ file = File.open(path)
+ yield file if block_given?
+ file.close
+ end
+
+ def csv(path)
+ file(path) do |f|
+ parsed_file = CSV::Reader.parse(f)
+ parsed_file.each do |row|
+ row.each {|v| v.trim! if v.respond_to? :trim! }
+ yield row if block_given?
+ end
+ end
+ end
+
+ def tsv(path)
+ file(path) do |f|
+ parsed_file = CSV::Reader.parse(f)
+ parsed_file.each do |row|
+ row.each {|v| v.trim! if v.respond_to? :trim! }
+ yield row if block_given?
+ end
+ end
+ end
+
+ def xml(path)
+ require 'hpricot' unless defined? Hpricot
+ file(path) do |f|
+ doc = Hpricot(f)
+ yield doc if block_given?
+ end
+ end
+
+ def run(reset_flag = false)
+ reset if reset_flag && respond_to?(:reset)
+ import
+ end
+
+ # :stopdoc:
+ VERSION = '1.0.0'
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
+ # :startdoc:
+
+ # Returns the version string for the library.
+ #
+ def self.version
+ VERSION
+ end
+
+ # Returns the library path for the module. If any arguments are given,
+ # they will be joined to the end of the libray path using
+ # <tt>File.join</tt>.
+ #
+ def self.libpath( *args )
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
+ end
+
+ # Returns the lpath for the module. If any arguments are given,
+ # they will be joined to the end of the path using
+ # <tt>File.join</tt>.
+ #
+ def self.path( *args )
+ args.empty? ? PATH : ::File.join(PATH, *args)
+ end
+
+ # Utility method used to rquire all files ending in .rb that lie in the
+ # directory below this file that has the same name as the filename passed
+ # in. Optionally, a specific _directory_ name can be passed in such that
+ # the _filename_ does not have to be equivalent to the directory.
+ #
+ def self.require_all_libs_relative_to( fname, dir = nil )
+ dir ||= ::File.basename(fname, '.*')
+ search_me = ::File.expand_path(
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
+
+ Dir.glob(search_me).sort.each {|rb| require rb}
+ end
+
+end # module SimpleImporter
+
+SimpleImporter.require_all_libs_relative_to __FILE__
+
+end # unless defined?
+
+# EOF
View
76 pkg/simple_importer-1.0.0/tasks/ann.rake
@@ -0,0 +1,76 @@
+# $Id$
+
+begin
+ require 'bones/smtp_tls'
+rescue LoadError
+ require 'net/smtp'
+end
+require 'time'
+
+namespace :ann do
+
+ file PROJ.ann_file do
+ puts "Generating #{PROJ.ann_file}"
+ File.open(PROJ.ann_file,'w') do |fd|
+ fd.puts("#{PROJ.name} version #{PROJ.version}")
+ fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
+ fd.puts(" #{PROJ.url}") if PROJ.url
+ fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
+ fd.puts
+ fd.puts("== DESCRIPTION")
+ fd.puts
+ fd.puts(PROJ.description)
+ fd.puts
+ fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
+ fd.puts
+ PROJ.ann_paragraphs.each do |p|
+ fd.puts "== #{p.upcase}"
+ fd.puts
+ fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
+ fd.puts
+ end
+ fd.puts PROJ.ann_text if PROJ.ann_text
+ end
+ end
+
+ desc "Create an announcement file"
+ task :announcement => PROJ.ann_file
+
+ desc "Send an email announcement"
+ task :email => PROJ.ann_file do
+ from = PROJ.ann_email[:from] || PROJ.email
+ to = Array(PROJ.ann_email[:to])
+
+ ### build a mail header for RFC 822
+ rfc822msg = "From: #{from}\n"
+ rfc822msg << "To: #{to.join(',')}\n"
+ rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
+ rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
+ rfc822msg << "\n"
+ rfc822msg << "Date: #{Time.new.rfc822}\n"
+ rfc822msg << "Message-Id: "
+ rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{PROJ.ann_email[:domain]}>\n\n"
+ rfc822msg << File.read(PROJ.ann_file)
+
+ params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
+ PROJ.ann_email[key]
+ end
+
+ params[3] = PROJ.email if params[3].nil?
+
+ if params[4].nil?
+ STDOUT.write "Please enter your e-mail password (#{params[3]}): "
+ params[4] = STDIN.gets.chomp
+ end
+
+ ### send email
+ Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
+ end
+end # namespace :ann
+
+desc 'Alias to ann:announcement'
+task :ann => 'ann:announcement'
+
+CLOBBER << PROJ.ann_file
+
+# EOF
View
22 pkg/simple_importer-1.0.0/tasks/annotations.rake
@@ -0,0 +1,22 @@
+# $Id$
+
+if HAVE_BONES
+
+desc "Enumerate all annotations"
+task :notes do
+ Bones::AnnotationExtractor.enumerate(
+ PROJ, PROJ.annotation_tags.join('|'), :tag => true)
+end
+
+namespace :notes do
+ PROJ.annotation_tags.each do |tag|
+ desc "Enumerate all #{tag} annotations"
+ task tag.downcase.to_sym do
+ Bones::AnnotationExtractor.enumerate(PROJ, tag)
+ end
+ end
+end
+
+end # if HAVE_BONES
+
+# EOF
View
40 pkg/simple_importer-1.0.0/tasks/bones.rake
@@ -0,0 +1,40 @@
+# $Id$
+
+require 'pp'
+require 'stringio'
+
+namespace :bones do
+
+ desc 'Show the PROJ open struct'
+ task :debug do |t|
+ atr = if ARGV.length == 2
+ t.application.top_level_tasks.pop
+ end
+ sio = StringIO.new
+ sep = "\n" + ' '*27
+ fmt = "%23s => %s"
+
+ if atr
+ PP.pp(PROJ.send(atr.to_sym), sio, 49)
+ sio.seek 0
+ val = sio.read
+ val = val.split("\n").join(sep)
+
+ puts fmt % [atr, val]
+ else
+ h = PROJ.instance_variable_get(:@table)
+ h.keys.map {|k| k.to_s}.sort.each do |k|
+ sio.truncate 0
+ PP.pp(h[k.to_sym], sio, 49)
+ sio.seek 0
+ val = sio.read
+ val = val.split("\n").join(sep)
+
+ puts fmt % [k, val]
+ end
+ end
+ end
+
+end # namespace :bones
+
+# EOF
View
48 pkg/simple_importer-1.0.0/tasks/doc.rake
@@ -0,0 +1,48 @@
+# $Id$
+
+require 'rake/rdoctask'
+
+namespace :doc do
+
+ desc 'Generate RDoc documentation'
+ Rake::RDocTask.new do |rd|
+ rd.main = PROJ.rdoc_main
+ rd.rdoc_dir = PROJ.rdoc_dir
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = Regexp.new(PROJ.rdoc_exclude.join('|'))
+ files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ rd.rdoc_files.push(*files)
+
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
+ title = "#{PROJ.rubyforge_name}'s " + title if PROJ.rubyforge_name != title
+
+ rd.options << "-t #{title}"
+ rd.options.concat(PROJ.rdoc_opts)
+ end
+
+ desc 'Generate ri locally for testing'
+ task :ri => :clobber_ri do
+ sh "#{RDOC} --ri -o ri ."
+ end
+
+ task :clobber_ri do
+ rm_r 'ri' rescue nil
+ end
+
+end # namespace :doc
+
+desc 'Alias to doc:rdoc'
+task :doc => 'doc:rdoc'
+
+desc 'Remove all build products'
+task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
+
+remove_desc_for_task %w(doc:clobber_rdoc)
+
+# EOF
View
116 pkg/simple_importer-1.0.0/tasks/gem.rake
@@ -0,0 +1,116 @@
+# $Id$
+
+require 'rake/gempackagetask'
+
+namespace :gem do
+
+ PROJ.spec = Gem::Specification.new do |s|
+ s.name = PROJ.name
+ s.version = PROJ.version
+ s.summary = PROJ.summary
+ s.authors = Array(PROJ.authors)
+ s.email = PROJ.email
+ s.homepage = Array(PROJ.url).first
+ s.rubyforge_project = PROJ.rubyforge_name
+ s.post_install_message = PROJ.post_install_message
+
+ s.description = PROJ.description
+
+ PROJ.dependencies.each do |dep|
+ s.add_dependency(*dep)
+ end
+
+ s.files = PROJ.files
+ s.executables = PROJ.executables.map {|fn| File.basename(fn)}
+ s.extensions = PROJ.files.grep %r/extconf\.rb$/
+
+ s.bindir = 'bin'
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
+ s.require_paths = dirs unless dirs.empty?
+
+ incl = Regexp.new(PROJ.rdoc_include.join('|'))
+ excl = PROJ.rdoc_exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
+ excl = Regexp.new(excl.join('|'))
+ rdoc_files = PROJ.files.find_all do |fn|
+ case fn
+ when excl; false
+ when incl; true
+ else false end
+ end
+ s.rdoc_options = PROJ.rdoc_opts + ['--main', PROJ.rdoc_main]
+ s.extra_rdoc_files = rdoc_files
+ s.has_rdoc = true
+
+ if test ?f, PROJ.test_file
+ s.test_file = PROJ.test_file
+ else
+ s.test_files = PROJ.tests.to_a
+ end
+
+ # Do any extra stuff the user wants
+# spec_extras.each do |msg, val|
+# case val
+# when Proc
+# val.call(s.send(msg))
+# else
+# s.send "#{msg}=", val
+# end
+# end
+ end
+
+ desc 'Show information about the gem'
+ task :debug do
+ puts PROJ.spec.to_ruby
+ end
+
+ pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
+ pkg.need_tar = PROJ.need_tar
+ pkg.need_zip = PROJ.need_zip
+ pkg.package_files += PROJ.spec.files
+ end
+ Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
+
+ gem_file = if PROJ.spec.platform == Gem::Platform::RUBY
+ "#{pkg.package_name}.gem"
+ else
+ "#{pkg.package_name}-#{PROJ.spec.platform}.gem"
+ end
+
+ desc "Build the gem file #{gem_file}"
+ task :package => "#{pkg.package_dir}/#{gem_file}"
+
+ file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.spec.files do
+ when_writing("Creating GEM") {
+ Gem::Builder.new(PROJ.spec).build
+ verbose(true) {
+ mv gem_file, "#{pkg.package_dir}/#{gem_file}"
+ }
+ }
+ end
+
+ desc 'Install the gem'
+ task :install => [:clobber, :package] do
+ sh "#{SUDO} #{GEM} install pkg/#{PROJ.spec.full_name}"
+ end
+
+ desc 'Uninstall the gem'
+ task :uninstall do
+ installed_list = Gem.source_index.find_name(PROJ.name)
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
+ sh "#{SUDO} #{GEM} uninstall -v '#{PROJ.version}' -i -x #{PROJ.name}"
+ end
+ end
+
+ desc 'Reinstall the gem'
+ task :reinstall => [:uninstall, :install]
+
+end # namespace :gem
+
+desc 'Alias to gem:package'
+task :gem => 'gem:package'
+
+task :clobber => 'gem:clobber_package'
+
+remove_desc_for_task %w(gem:clobber_package)
+
+# EOF
View
49 pkg/simple_importer-1.0.0/tasks/manifest.rake
@@ -0,0 +1,49 @@
+# $Id$
+
+require 'find'
+
+namespace :manifest do
+
+ desc 'Verify the manifest'
+ task :check do
+ fn = PROJ.manifest_file + '.tmp'
+ files = manifest_files
+
+ File.open(fn, 'w') {|fp| fp.puts files}
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
+ lines.map! do |line|
+ case line
+ when %r/^(-{3}|\+{3})/; nil
+ when %r/^@/; Console::ANSICode.blue line
+ when %r/^\+/; Console::ANSICode.green line
+ when %r/^\-/; Console::ANSICode.red line
+ else line end
+ end
+ end
+ puts lines.compact
+ rm fn rescue nil
+ end
+
+ desc 'Create a new manifest'
+ task :create do
+ files = manifest_files
+ unless test(?f, PROJ.manifest_file)
+ files << PROJ.manifest_file
+ files.sort!
+ end
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
+ end
+
+ task :assert do
+ files = manifest_files
+ manifest = File.read(PROJ.manifest_file).split($/)
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
+ end
+
+end # namespace :manifest
+
+desc 'Alias to manifest:check'
+task :manifest => 'manifest:check'
+
+# EOF
View
32 pkg/simple_importer-1.0.0/tasks/post_load.rake
@@ -0,0 +1,32 @@
+# $Id$
+
+# This file does not define any rake tasks. It is used to load some project
+# settings if they are not defined by the user.
+
+PROJ.rdoc_exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
+PROJ.exclude << "^#{Regexp.escape(PROJ.ann_file)}$"
+
+PROJ.instance_variable_get(:@table).each do |key,val|
+ next unless val.instance_of? Array
+ next if key == :dependencies
+ val.flatten!
+end
+
+PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
+
+PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
+
+PROJ.summary ||= PROJ.description.split('.').first
+
+PROJ.files ||=
+ if test(?f, PROJ.manifest_file)
+ files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
+ files.delete ''
+ files
+ else [] end
+
+PROJ.executables ||= PROJ.files.find_all {|fn| fn =~ %r/^bin/}
+
+PROJ.rdoc_main ||= PROJ.readme_file
+
+# EOF
View
57 pkg/simple_importer-1.0.0/tasks/rubyforge.rake
@@ -0,0 +1,57 @@
+# $Id$
+
+if PROJ.rubyforge_name && HAVE_RUBYFORGE
+
+require 'rubyforge'
+require 'rake/contrib/sshpublisher'
+
+namespace :gem do
+ desc 'Package and upload to RubyForge'
+ task :release => [:clobber, :package] do |t|
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
+ pkg = "pkg/#{PROJ.spec.full_name}"
+
+ if $DEBUG then
+ puts "release_id = rf.add_release #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
+ puts "rf.add_file #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
+ end
+
+ rf = RubyForge.new
+ puts 'Logging in'
+ rf.login
+
+ c = rf.userconfig
+ c['release_notes'] = PROJ.description if PROJ.description
+ c['release_changes'] = PROJ.changes if PROJ.changes
+ c['preformatted'] = true
+
+ files = [(PROJ.need_tar ? "#{pkg}.tgz" : nil),
+ (PROJ.need_zip ? "#{pkg}.zip" : nil),
+ "#{pkg}.gem"].compact
+
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
+ rf.add_release PROJ.rubyforge_name, PROJ.name, PROJ.version, *files
+ end
+end # namespace :gem
+
+
+namespace :doc do
+ desc "Publish RDoc to RubyForge"
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
+ config = YAML.load(
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+ )
+
+ host = "#{config['username']}@rubyforge.org"
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
+ remote_dir << PROJ.rdoc_remote_dir if PROJ.rdoc_remote_dir
+ local_dir = PROJ.rdoc_dir
+
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
+ end
+end # namespace :doc
+
+end # if HAVE_RUBYFORGE
+
+# EOF
View
227 pkg/simple_importer-1.0.0/tasks/setup.rb
@@ -0,0 +1,227 @@
+# $Id$
+
+require 'rubygems'
+require 'rake'
+require 'rake/clean'
+require 'fileutils'
+require 'ostruct'
+
+PROJ = OpenStruct.new
+
+PROJ.name = nil
+PROJ.summary = nil
+PROJ.description = nil
+PROJ.changes = nil
+PROJ.authors = nil
+PROJ.email = nil
+PROJ.url = nil
+PROJ.version = ENV['VERSION'] || '0.0.0'
+PROJ.rubyforge_name = nil
+PROJ.exclude = %w(tmp$ bak$ ~$ CVS .svn/ ^pkg/ ^doc/)
+PROJ.release_name = ENV['RELEASE']
+PROJ.history_file = 'History.txt'
+PROJ.manifest_file = 'Manifest.txt'
+PROJ.readme_file = 'README.txt'
+
+# Rspec
+PROJ.specs = FileList['spec/**/*_spec.rb']
+PROJ.spec_opts = []
+
+# Test::Unit
+PROJ.tests = FileList['test/**/test_*.rb']
+PROJ.test_file = 'test/all.rb'
+PROJ.test_opts = []
+
+# Rcov
+PROJ.rcov_dir = 'coverage'
+PROJ.rcov_opts = %w[--sort coverage -T]
+PROJ.rcov_threshold = 90.0
+PROJ.rcov_threshold_exact = false
+
+# Rdoc
+PROJ.rdoc_opts = []
+PROJ.rdoc_include = %w(^lib/ ^bin/ ^ext/ .txt$)
+PROJ.rdoc_exclude = %w(extconf.rb$)
+PROJ.rdoc_main = nil
+PROJ.rdoc_dir = 'doc'
+PROJ.rdoc_remote_dir = nil
+
+# Extensions
+PROJ.extensions = FileList['ext/**/extconf.rb']
+PROJ.ruby_opts = %w(-w)
+PROJ.libs = []
+%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
+
+# Gem Packaging
+PROJ.files = nil
+PROJ.executables = nil
+PROJ.dependencies = []
+PROJ.need_tar = true
+PROJ.need_zip = false
+PROJ.post_install_message = nil
+
+# File Annotations
+PROJ.annotation_exclude = %w(^tasks/setup.rb$)
+PROJ.annotation_extensions = %w(.txt .rb .erb) << ''
+PROJ.annotation_tags = %w(FIXME OPTIMIZE TODO)
+
+# Subversion Repository
+PROJ.svn = false
+PROJ.svn_root = nil
+PROJ.svn_trunk = 'trunk'
+PROJ.svn_tags = 'tags'
+PROJ.svn_branches = 'branches'
+
+# Announce
+PROJ.ann_file = 'announcement.txt'
+PROJ.ann_text = nil
+PROJ.ann_paragraphs = []
+PROJ.ann_email = {
+ :from => nil,
+ :to => %w(ruby-talk@ruby-lang.org),
+ :server => 'localhost',
+ :port => 25,
+ :domain => ENV['HOSTNAME'],
+ :acct => nil,
+ :passwd => nil,
+ :authtype => :plain
+}
+
+# Load the other rake files in the tasks folder
+rakefiles = Dir.glob('tasks/*.rake').sort
+rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
+import(*rakefiles)
+
+# Setup some constants
+WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
+
+DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
+
+def quiet( &block )
+ io = [STDOUT.dup, STDERR.dup]
+ STDOUT.reopen DEV_NULL
+ STDERR.reopen DEV_NULL
+ block.call
+ensure
+ STDOUT.reopen io.first
+ STDERR.reopen io.last
+end
+
+DIFF = if WIN32 then 'diff.exe'
+ else
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
+ else 'diff' end
+ end unless defined? DIFF
+
+SUDO = if WIN32 then ''
+ else
+ if quiet {system 'which sudo'} then 'sudo'
+ else '' end
+ end
+
+RCOV = WIN32 ? 'rcov.bat' : 'rcov'
+GEM = WIN32 ? 'gem.bat' : 'gem'
+
+%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
+ begin
+ require lib
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
+ rescue LoadError
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
+ end
+end
+
+# Reads a file at +path+ and spits out an array of the +paragraphs+
+# specified.
+#
+# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
+# summary, *description = paragraphs_of('README.txt', 3, 3..8)
+#
+def paragraphs_of( path, *paragraphs )
+ title = String === paragraphs.first ? paragraphs.shift : nil
+ ary = File.read(path).delete("\r").split(/\n\n+/)
+
+ result = if title
+ tmp, matching = [], false
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
+ paragraphs << (0..-1) if paragraphs.empty?
+
+ ary.each do |val|
+ if val =~ rgxp
+ break if matching
+ matching = true
+ rgxp = %r/^=+/i
+ elsif matching
+ tmp << val
+ end
+ end
+ tmp
+ else ary end
+
+ result.values_at(*paragraphs)
+end
+
+# Adds the given gem _name_ to the current project's dependency list. An
+# optional gem _version_ can be given. If omitted, the newest gem version
+# will be used.
+#
+def depend_on( name, version = nil )
+ spec = Gem.source_index.find_name(name).last
+ version = spec.version.to_s if version.nil? and !spec.nil?
+
+ PROJ.dependencies << case version
+ when nil; [name]
+ when %r/^\d/; [name, ">= #{version}"]
+ else [name, version] end
+end
+
+# Adds the given arguments to the include path if they are not already there
+#
+def ensure_in_path( *args )
+ args.each do |path|
+ path = File.expand_path(path)
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
+ end
+end
+
+# Find a rake task using the task name and remove any description text. This
+# will prevent the task from being displayed in the list of available tasks.
+#
+def remove_desc_for_task( names )
+ Array(names).each do |task_name|
+ task = Rake.application.tasks.find {|t| t.name == task_name}
+ next if task.nil?
+ task.instance_variable_set :@comment, nil
+ end
+end
+
+# Change working directories to _dir_, call the _block_ of code, and then
+# change back to the original working directory (the current directory when
+# this method was called).
+#
+def in_directory( dir, &block )
+ curdir = pwd
+ begin
+ cd dir
+ return block.call
+ ensure
+ cd curdir
+ end
+end
+
+# Scans the current working directory and creates a list of files that are
+# candidates to be in the manifest.
+#
+def manifest_files
+ files = []
+ exclude = Regexp.new(PROJ.exclude.join('|'))
+ Find.find '.' do |path|
+ path.sub! %r/^(\.\/|\/)/o, ''
+ next unless test ?f, path
+ next if path =~ exclude
+ files << path
+ end
+ files.sort!
+end
+
+# EOF
View
38 pkg/simple_importer-1.0.0/tasks/test.rake
@@ -0,0 +1,38 @@
+# $Id$
+
+require 'rake/testtask'
+
+namespace :test do
+
+ Rake::TestTask.new(:run) do |t|
+ t.libs = PROJ.libs
+ t.test_files = if test(?f, PROJ.test_file) then [PROJ.test_file]
+ else PROJ.tests end
+ t.ruby_opts += PROJ.ruby_opts
+ t.ruby_opts += PROJ.test_opts
+ end
+
+ if HAVE_RCOV
+ desc 'Run rcov on the unit tests'
+ task :rcov => :clobber_rcov do
+ opts = PROJ.rcov_opts.dup << '-o' << PROJ.rcov_dir
+ opts = opts.join(' ')
+ files = if test(?f, PROJ.test_file) then [PROJ.test_file]
+ else PROJ.tests end
+ files = files.join(' ')
+ sh "#{RCOV} #{files} #{opts}"
+ end
+
+ task :clobber_rcov do
+ rm_r 'coverage' rescue nil
+ end
+ end
+
+end # namespace :test
+
+desc 'Alias to test:run'
+task :test => 'test:run'
+
+task :clobber => 'test:clobber_rcov' if HAVE_RCOV
+
+# EOF
View
3  pkg/simple_importer-1.0.0/test/test_helper.rb
@@ -0,0 +1,3 @@
+require 'rubygems'
+require 'test/spec'
+require 'mocha'
View
1  pkg/simple_importer-1.0.0/test/test_simple_importer.rb
@@ -0,0 +1 @@
+require 'test_helper'
Please sign in to comment.
Something went wrong with that request. Please try again.