Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 486d0881869a0f709360a5de6e98d3a6c52abb78 @ddollar committed Jun 13, 2008
@@ -0,0 +1,5 @@
+*.gemspec
+doc/coverage
+doc/rdoc
+output
+pkg
No changes.
@@ -0,0 +1,108 @@
+require 'rubygems'
+require 'erb'
+require 'yaml'
+require 'rake'
+require 'rake/rdoctask'
+require 'spec/rake/spectask'
+require 'spec/rake/verify_rcov'
+
+task :default => [ 'rspec:run' ]
+
+namespace :gem do
+
+ task :config do
+ @config = OpenStruct.new
+
+ File.open("config/gem.rb", "r") do |gem_config|
+ eval(gem_config.read)
+ end
+
+ @config.files = FileList["{bin,doc,lib,test}/**/*"].to_a.map do |file|
+ '"' + file + '"'
+ end.join(',')
+ end
+
+ desc "Build the gem"
+ task :build => [ 'gem:config', 'gem:spec:build' ] do
+ spec = nil
+ File.open("#{@config.name}.gemspec", 'r') do |gemspec|
+ eval gemspec.read
+ end
+ Gem::manage_gems
+ gemfile = Gem::Builder.new(spec).build
+ Dir.mkdir('pkg') unless File.exists?('pkg')
+ File.rename(gemfile, "pkg/#{gemfile}")
+ end
+
+ namespace :spec do
+
+ desc "Build gemspec"
+ task :build => [ :config ] do
+ File.open("config/gemspec.rb.erb", "r") do |template|
+ File.open("#{@config.name}.gemspec", "w") do |gemspec|
+ template_data = "<% config = YAML::load(%{#{Regexp.escape(YAML::dump(@config))}}) %>\n"
+ template_data += template.read
+ original_stdout = $stdout
+ $stdout = gemspec
+ ERB.new(template_data).run
+ $stdout = original_stdout
+ end
+ end
+ end
+
+ desc "Test gemspec against Github"
+ task :test => [ 'gem:config', :build ] do
+ require 'rubygems/specification'
+ data = File.read("#{@config.name}.gemspec")
+ spec = nil
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
+ puts spec
+ end
+
+ end
+end
+
+namespace :rdoc do
+
+ desc 'Generate RDoc'
+ rd = Rake::RDocTask.new(:build) do |rdoc|
+ Rake::Task['gem:config'].invoke
+ rdoc.title = @config.name
+ rdoc.main = 'README'
+ rdoc.rdoc_dir = 'output/rdoc'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README', 'lib/**/*.rb')
+ end
+
+ desc 'View RDoc'
+ task :view => [ :build ] do
+ system %{open output/rdoc/index.html}
+ end
+
+end
+
+namespace :rspec do
+
+ desc "Run rspec tasks"
+ Spec::Rake::SpecTask.new(:run) do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ #t.spec_opts = ['--options', 'spec/spec.opts']
+ unless ENV['NO_RCOV']
+ t.rcov = true
+ t.rcov_dir = 'output/coverage'
+ t.rcov_opts = ['--exclude', 'bin\/rtr,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest']
+ end
+ end
+
+ desc "Show code coverage"
+ task :coverage => [ :run ] do
+ system %{open output/coverage/index.html}
+ end
+
+ desc "Verify code coverage"
+ RCov::VerifyTask.new(:verify => :run) do |t|
+ t.threshold = 100.0
+ t.index_html = 'output/coverage/index.html'
+ end
+
+end
No changes.
@@ -0,0 +1,10 @@
+@config.name = "generic"
+
+require "lib/#{@config.name}"
+
+@config.version = Generic.version
+@config.summary = "Summary Here"
+@config.homepage = "http://peervoice.com/software/#{@config.name}"
+
+@config.author_name = "David Dollar"
+@config.author_email = "ddollar@gmail.com"
@@ -0,0 +1,19 @@
+spec = Gem::Specification.new do |s|
+
+ s.name = "<%= config.name %>"
+ s.version = "<%= config.version %>"
+ s.summary = "<%= config.summary %>"
+ s.homepage = "<%= config.homepage %>"
+
+ s.author = "<%= config.author_name %>"
+ s.email = "<%= config.author_email %>"
+
+ s.files = [<%= config.files %>]
+ s.platform = Gem::Platform::RUBY
+
+ s.rubyforge_project = "<%= config.name %>"
+ s.require_path = "lib"
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README"]
+
+end
No changes.
@@ -0,0 +1,49 @@
+# Equivalent to a header guard in C/C++
+# Used to prevent the class/module from being loaded more than once
+unless defined? Generic
+
+module Generic
+
+ # :stopdoc:
+ VERSION = '0.0.1'
+ 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)
+ search_me = File.expand_path(File.join(File.dirname(fname), '**', '*.rb'))
+ Dir.glob(search_me).sort.each { |rb| require rb }
+ end
+
+end
+
+Generic.require_all_libs_relative_to __FILE__
+
+end # unless defined?
No changes.
@@ -0,0 +1,23 @@
+$:.push('lib')
+require 'generic'
+include Generic
+
+describe Generic do
+
+ describe 'rspec' do
+
+ it "should have a version" do
+ lambda { Generic.version }.should_not raise_error
+ end
+
+ it "should have a libpath" do
+ lambda { Generic.libpath }.should_not raise_error
+ end
+
+ it "should have a path" do
+ lambda { Generic.path }.should_not raise_error
+ end
+
+ end
+
+end

0 comments on commit 486d088

Please sign in to comment.