Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

one nation under rakegem

  • Loading branch information...
commit c2ff1f0be3d0238fb4832ff7aae18e67f3778a44 1 parent d39c303
@holman holman authored
Showing with 276 additions and 17 deletions.
  1. +1 −10 Gemfile
  2. +144 −7 Rakefile
  3. +3 −0  lib/play.rb
  4. +128 −0 play.gemspec
View
11 Gemfile
@@ -1,11 +1,2 @@
source 'http://rubygems.org'
-gem 'rack', '~>1.2.2'
-gem 'sinatra'
-gem 'activerecord', :require => 'active_record'
-gem 'sqlite3'
-gem 'mustache'
-gem 'SystemTimer'
-gem 'ruby-audioinfo'
-gem 'oa-oauth'
-gem 'yajl-ruby'
-gem 'mysql2'
+gemspec
View
151 Rakefile
@@ -1,4 +1,83 @@
+require 'rubygems'
+require 'rake'
+require 'date'
+
+#############################################################################
+#
+# Helper functions
+#
+#############################################################################
+
+def name
+ @name ||= Dir['*.gemspec'].first.split('.').first
+end
+
+def version
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+end
+
+def date
+ Date.today.to_s
+end
+
+def rubyforge_project
+ name
+end
+
+def gemspec_file
+ "#{name}.gemspec"
+end
+
+def gem_file
+ "#{name}-#{version}.gem"
+end
+
+def replace_header(head, header_name)
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
+end
+
+#############################################################################
+#
+# Standard tasks
#
+#############################################################################
+
+task :default => :test
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+desc "Generate RCov test coverage and open in your browser"
+task :coverage do
+ require 'rcov'
+ sh "rm -fr coverage"
+ sh "rcov test/test_*.rb"
+ sh "open coverage/index.html"
+end
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "#{name} #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+desc "Open an irb session preloaded with this library"
+task :console do
+ sh "irb -rubygems -r ./lib/#{name}.rb"
+end
+
+#############################################################################
+#
+# Custom tasks (add your own tasks here)
+#
+#############################################################################
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
@@ -37,12 +116,70 @@ namespace :db do
end
end
-task :default => :test
+#############################################################################
+#
+# Packaging tasks
+#
+#############################################################################
-desc "Run tests"
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
+desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
+task :release => :build do
+ unless `git branch` =~ /^\* master$/
+ puts "You must be on the master branch to release!"
+ exit!
+ end
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
+ sh "git tag v#{version}"
+ sh "git push origin master"
+ sh "git push origin v#{version}"
+ sh "gem push pkg/#{name}-#{version}.gem"
+end
+
+desc "Build #{gem_file} into the pkg directory"
+task :build => :gemspec do
+ sh "mkdir -p pkg"
+ sh "gem build #{gemspec_file}"
+ sh "mv #{gem_file} pkg"
+end
+
+desc "Generate #{gemspec_file}"
+task :gemspec => :validate do
+ # read spec file and split out manifest section
+ spec = File.read(gemspec_file)
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
+
+ # replace name version and date
+ replace_header(head, :name)
+ replace_header(head, :version)
+ replace_header(head, :date)
+ #comment this out if your rubyforge_project has a different name
+ replace_header(head, :rubyforge_project)
+
+ # determine file list from git ls-files
+ files = `git ls-files`.
+ split("\n").
+ sort.
+ reject { |file| file =~ /^\./ }.
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
+ map { |file| " #{file}" }.
+ join("\n")
+
+ # piece file back together and write
+ manifest = " s.files = %w[\n#{files}\n ]\n"
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
+ puts "Updated #{gemspec_file}"
+end
+
+desc "Validate #{gemspec_file}"
+task :validate do
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
+ unless libfiles.empty?
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
+ exit!
+ end
+ unless Dir['VERSION*'].empty?
+ puts "A `VERSION` file at root level violates Gem best practices."
+ exit!
+ end
end
View
3  lib/play.rb
@@ -25,6 +25,9 @@
require 'play/vote'
module Play
+
+ VERSION = '0.0.1'
+
# The path to your music library. All of the music underneath this directory
# will be added to the internal library.
#
View
128 play.gemspec
@@ -0,0 +1,128 @@
+## This is the rakegem gemspec template. Make sure you read and understand
+## all of the comments. Some sections require modification, and others can
+## be deleted if you don't need them. Once you understand the contents of
+## this file, feel free to delete any comments that begin with two hash marks.
+## You can find comprehensive Gem::Specification documentation, at
+## http://docs.rubygems.org/read/chapter/20
+Gem::Specification.new do |s|
+ s.specification_version = 2 if s.respond_to? :specification_version=
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.rubygems_version = '1.3.5'
+
+ ## Leave these as is they will be modified for you by the rake gemspec task.
+ ## If your rubyforge_project name is different, then edit it and comment out
+ ## the sub! line in the Rakefile
+ s.name = 'play'
+ s.version = '0.0.1'
+ s.date = '2011-05-05'
+ s.rubyforge_project = 'play'
+
+ ## Make sure your summary is short. The description may be as long
+ ## as you like.
+ s.summary = "Your company's dj. ►"
+ s.description = "We want to play music at our office. Everyone has their own
+ library on their own machines, and everyone except for me plays shitty music.
+ Play is designed to make office music more palatable."
+
+ ## List the primary authors. If there are a bunch of authors, it's probably
+ ## better to set the email to an email list or something. If you don't have
+ ## a custom homepage, consider using your GitHub URL or the like.
+ s.authors = ["Zach Holman"]
+ s.email = 'github.com@zachholman.com'
+ s.homepage = 'https://github.com/holman/play'
+
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
+ s.require_paths = %w[lib]
+
+ ## If your gem includes any executables, list them here.
+ s.executables = ["play"]
+ s.default_executable = 'play'
+
+ ## Specify any RDoc options here. You'll want to add your README and
+ ## LICENSE files to the extra_rdoc_files list.
+ #s.rdoc_options = ["--charset=UTF-8"]
+ #s.extra_rdoc_files = %w[README LICENSE]
+
+ ## List your runtime dependencies here. Runtime dependencies are those
+ ## that are needed for an end user to actually USE your code.
+ s.add_dependency('rack', ["~>1.2.2"])
+ s.add_dependency('sinatra')
+ s.add_dependency('activerecord')
+ s.add_dependency('sqlite3')
+ s.add_dependency('mustache')
+ s.add_dependency('SystemTimer')
+ s.add_dependency('ruby-audioinfo')
+ s.add_dependency('oa-oauth')
+ s.add_dependency('yajl-ruby')
+ s.add_dependency('mysql2')
+
+ ## List your development dependencies here. Development dependencies are
+ ## those that are only needed during development
+ s.add_development_dependency('running_man')
+ s.add_development_dependency('mocha')
+
+ ## Leave this section as-is. It will be automatically generated from the
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
+ # = MANIFEST =
+ s.files = %w[
+ Gemfile
+ Gemfile.lock
+ README.md
+ Rakefile
+ bin/play
+ config.ru
+ db/migrate/01_create_schema.rb
+ lib/play.rb
+ lib/play/album.rb
+ lib/play/app.rb
+ lib/play/app/api.rb
+ lib/play/artist.rb
+ lib/play/client.rb
+ lib/play/core_ext/hash.rb
+ lib/play/history.rb
+ lib/play/library.rb
+ lib/play/office.rb
+ lib/play/song.rb
+ lib/play/templates/album_songs.mustache
+ lib/play/templates/artist_songs.mustache
+ lib/play/templates/index.mustache
+ lib/play/templates/layout.mustache
+ lib/play/templates/now_playing.mustache
+ lib/play/templates/play_history.mustache
+ lib/play/templates/profile.mustache
+ lib/play/templates/search.mustache
+ lib/play/templates/show_song.mustache
+ lib/play/templates/song.mustache
+ lib/play/user.rb
+ lib/play/views/album_songs.rb
+ lib/play/views/artist_songs.rb
+ lib/play/views/index.rb
+ lib/play/views/layout.rb
+ lib/play/views/now_playing.rb
+ lib/play/views/play_history.rb
+ lib/play/views/profile.rb
+ lib/play/views/search.rb
+ lib/play/views/show_song.rb
+ lib/play/vote.rb
+ play.yml.example
+ public/css/base.css
+ test/helper.rb
+ test/spec/mini.rb
+ test/test_api.rb
+ test/test_app.rb
+ test/test_artist.rb
+ test/test_client.rb
+ test/test_library.rb
+ test/test_office.rb
+ test/test_play.rb
+ test/test_song.rb
+ test/test_user.rb
+ ]
+ # = MANIFEST =
+
+ ## Test files will be grabbed from the file list. Make sure the path glob
+ ## matches what you actually use.
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
+end
Please sign in to comment.
Something went wrong with that request. Please try again.