Sha256: 596b4453b05b3da71d9a5b6fc41cff400d29b773eef206c2a400bf5f88ff42a5
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
require 'bundler' module Dionysus module TravisCI class GemfileGenerator def initialize(gemfile) @definition = Bundler::Dsl.new @definition.instance_eval(Bundler.read_file(gemfile), "Gemfile", 1) end def generate(filename, options={}) File.open(filename, "w") do |f| f.puts %(source "http://rubygems.org") @definition.dependencies.each do |dep| next if exclude_by_group?(dep, :default, options[:without]) f.puts dependency_line(dep) end case options[:add] when String f.puts options[:add] when Array options[:add].each {|ln| f.puts ln} else raise "Invalid :add option: %p"%[options[:add]] if options[:add] end f.puts %(gemspec :path => "../") end end private def dependency_line(dep) ln = [ %(gem "%s")%[dep.name] ] ln << %("%s")%[dep.requirement] groups = dep.groups.collect {|v| %(:#{v})}.join(", ") ln << %(:group => [%s])%[groups] if dep.autorequire == [] ln << %(:require => false) elsif dep.autorequire requires = dep.autorequire.collect {|s| %("#{s}")}.join(",") ln << %(:require => [%s])%[requires] end if dep.source and dep.source.is_a?(Bundler::Source::Git) ln << %(:git => "%s")%[dep.source.options["git"]] ln << %(:branch => "%s")%[dep.source.options["branch"]] elsif dep.source raise "Unknown source type: %s"%[dep.source.class] end ln.join(", ") end def exclude_by_group?(dep, *without) return false if without.nil? or without.empty? without = without.compact.flatten !(dep.groups & without).empty? end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dionysus-2.1.0 | lib/dionysus/travisci/gemfile_generator.rb |
dionysus-2.0.0 | lib/dionysus/travisci/gemfile_generator.rb |