Permalink
Browse files

Use a context object instead. Slightly better dependencies.

  • Loading branch information...
1 parent 4cc367c commit 890be95beca7db6b30207cbf201ed014fd799ab0 @technicalpickles committed May 20, 2008
Showing with 50 additions and 13 deletions.
  1. +7 −5 ebuild.eruby
  2. +43 −8 g-gem.rb
View
@@ -6,16 +6,18 @@ inherit gems
DESCRIPTION="<%= spec.summary %>"
HOMEPAGE="<%= spec.homepage %>"
-SRC_URI="<%= source %>/gems/<%= spec.name %>-<%= spec.version.version %>.gem"
+SRC_URI="<%= uri %>"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64-linux ~ia64-linux ~x86-linux ~ppc-macos ~x86-macos ~sparc-solaris ~x86-solaris"
IUSE=""
RESTRICT="test"
+<%- unless spec.dependencies.empty? -%>
DEPEND="
- <% spec.dependencies.each do |dependency| %>
- dev-ruby/<%= dependency.name %>
- <% end %>
-"
+ <%- spec.dependencies.each do |dependency| -%>
+ <%= atom_of(dependency) %>
+ <%- end -%>
+"
+<%- end -%>
View
@@ -6,17 +6,52 @@
require 'ruby-debug'
require 'erubis'
+package = ARGV.first || 'activerecord'
+
inst = Gem::DependencyInstaller.new
-specs = inst.find_spec_by_name_and_version('activerecord')
+specs = inst.find_spec_by_name_and_version(package)
+
-input = File.read('ebuild.eruby')
-eruby = Erubis::Eruby.new(input)
-FileUtils.mkdir_p('ebuilds')
+class Ebuild
+ attr_accessor :spec, :source
+
+ def initialize(spec_pair)
+ @spec, @source = spec_pair
+ end
+
+ def filename
+ "#{spec.name.downcase}-#{spec.version.version}.ebuild"
+ end
+
+ def atom_of(dependency)
+ "dev-ruby/#{dependency.name}"
+ end
+
+ def uri
+ "#{source}/gems/#{spec.name}-#{spec.version.version}.gem"
+ end
+
+ def write
+ output = eruby.evaluate(self)
+ FileUtils.mkdir_p('ebuilds')
+ File.open(filename, 'w') {|f| f.write(output) }
+ end
+
+ protected
+
+ def eruby
+ unless @eruby
+ input = File.read('ebuild.eruby')
+ @eruby = Erubis::Eruby.new(input)
+ end
+ @eruby
+ end
+
+end
specs.each do |spec_pair|
- spec, source = spec_pair
- filename = "#{spec.name.downcase}-#{spec.version.version}.ebuild"
- output = eruby.result binding
- File.open(filename, 'w') {|f| f.write(output) }
+ ebuild = Ebuild.new(spec_pair)
+
+ ebuild.write
end

0 comments on commit 890be95

Please sign in to comment.