# # parse_dependencies_for # def parse_project_gemfile required_gems = [] gem_file = "#{project_dir}/lib/#{project[:name]}/gems.rb" if File.exist? gem_file # puts "Parsing gemfile #{gem_file}" code = File.open(gem_file){|f| f.read} stub_class = Class.new stub_class.send(:define_method, :gem){|*args| required_gems << args} stub = stub_class.new stub.instance_eval code, __FILE__, __LINE__ end required_gems end # # Install gems # namespace :gem do desc "Install gem required by project" task :install do gems = parse_project_gemfile gems.each do |name, version| puts "Installing gem #{name} #{version}" %x(gem install #{name} #{"-v #{version}" if version}) end end end # # Gem Spec, for sample look at Rakefile # require 'rake/clean' require 'rake/gempackagetask' require 'tmpdir' namespace :gem do spec = Gem::Specification.new do |s| gems = parse_project_gemfile gems.each{|name_version| s.add_dependency *name_version} options = project.clone options.delete(:name) s.name = options.delete(:gem_name) s.platform = options.delete(:platform) || Gem::Platform::RUBY s.has_rdoc = options.delete(:has_rdoc) == nil ? false : true s.require_path = options.delete(:lib) || "lib" s.files = options.delete(:files) || (%w{Rakefile readme.md} + Dir.glob("{lib,spec}/**/*")) # s.name = options[:name) # s.author = options[:author) # s.homepage = options[:homepage) options.each{|k, v| s.send "#{k}=", v} end package_dir = Dir.tmpdir + "/#{project[:gem_name]}_tmp" Rake::GemPackageTask.new(spec) do |p| p.need_tar = true if RUBY_PLATFORM !~ /mswin/ p.need_zip = true p.package_dir = package_dir end task :push do gem_file = Dir.glob("#{package_dir}/#{project[:gem_name]}*.gem").first system "gem push #{gem_file}" end task :clean do system "rm -r #{package_dir}" end desc "List all gems required by project" task :list do puts "Gems required for #{project[:gem_name]}:" puts parse_project_gemfile end desc "Build and publish project as gem" task :release => [:gem, :push, :clean] end