Skip to content

Commit

Permalink
Adds Code for generating a gemspec for github
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neighman committed Apr 25, 2008
1 parent 4bb3861 commit 7d14e7e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Rakefile
Expand Up @@ -85,6 +85,40 @@ task :uninstall => :clean do
sh %{#{SUDO} gem uninstall #{NAME}}
end

namespace :github do
desc "Update Github Gemspec"
task :update_gemspec do
skip_fields = %w(new_platform original_platform)
integer_fields = %w(specification_version)

result = "Gem::Specification.new do |s|\n"
spec.instance_variables.each do |ivar|
value = spec.instance_variable_get(ivar)
name = ivar.split("@").last
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
if name == "dependencies"
value.each do |d|
dep, *ver = d.to_s.split(" ")
result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "")}\n"
end
else
case value
when Array
value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
when String
value = value.to_i if integer_fields.include?(name)
value = value.inspect
else
value = value.to_s.inspect
end
result << " s.#{name} = #{value}\n"
end
end
result << "end"
File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
end
end

##############################################################################
# Documentation
##############################################################################
Expand Down

2 comments on commit 7d14e7e

@drbrain
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is terrible!

Use Gem::Specification#to_ruby!

It existed all the way back to 0.8.11!

With documentation!

@raggi
Copy link

@raggi raggi commented on 7d14e7e Jul 31, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL.

Please sign in to comment.