lib/jeweler/gemspec.rb in technicalpickles-jeweler-0.6.2 vs lib/jeweler/gemspec.rb in technicalpickles-jeweler-0.6.3

- old
+ new

@@ -1,53 +1,41 @@ class Jeweler - module Gemspec - # Writes out the gemspec - def write_gemspec - self.refresh_version - @gemspec.version = self.version - @gemspec.date = Time.now - File.open(gemspec_path, 'w') do |f| - f.write @gemspec.to_ruby - end - puts "Generated: #{gemspec_path}" - end - # Validates the gemspec in an environment similar to how GitHub would build - # it. See http://gist.github.com/16215 - def validate_gemspec - begin - parse_gemspec - puts "#{gemspec_path} is valid." - rescue Exception => e - puts "#{gemspec_path} is invalid. See the backtrace for more details." - raise - end - end + class GemSpecHelper + attr_accessor :spec, :base_dir - def valid_gemspec? + def initialize(spec, base_dir = nil) + self.spec = spec + self.base_dir = base_dir || '' + + yield spec if block_given? + end + + def valid? begin - parse_gemspec + parse true - rescue Exception => e + rescue false end end - - def parse_gemspec(data = nil) - data ||= File.read(gemspec_path) - Thread.new { eval("$SAFE = 3\n#{data}", binding, gemspec_path) }.join + + def write + File.open(path, 'w') do |f| + f.write @spec.to_ruby + end end - def unsafe_parse_gemspec(data = nil) - data ||= File.read(gemspec_path) - eval(data, binding, gemspec_path) + def path + denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec") + absolute_path = File.expand_path(denormalized_path) + absolute_path.gsub(Dir.getwd + File::SEPARATOR, '') end - protected - def gemspec_path - denormalized_path = File.join(@base_dir, "#{@gemspec.name}.gemspec") - absolute_path = File.expand_path(denormalized_path) - absolute_path.gsub(Dir.getwd + File::SEPARATOR, '') + def parse + data = File.read(path) + Thread.new { eval("$SAFE = 3\n#{data}", binding, path) }.join end + end end