lib/appraisal/gemfile.rb in appraisal-1.0.0.beta3 vs lib/appraisal/gemfile.rb in appraisal-1.0.0
- old
+ new
@@ -1,21 +1,26 @@
-require 'appraisal/dependency'
+require 'appraisal/dependency_list'
require 'appraisal/gemspec'
+require 'appraisal/git_source'
+require 'appraisal/path_source'
+require 'appraisal/group'
+require 'appraisal/platform'
module Appraisal
# Load bundler Gemfiles and merge dependencies
class Gemfile
attr_reader :dependencies
def initialize
@sources = []
@ruby_version = nil
- @dependencies = []
+ @dependencies = DependencyList.new
@gemspec = nil
- @groups = []
- @platforms = []
- @git_sources = []
+ @groups = {}
+ @platforms = {}
+ @git_sources = {}
+ @path_sources = {}
end
def load(path)
run(IO.read(path))
end
@@ -23,30 +28,23 @@
def run(definitions)
instance_eval(definitions, __FILE__, __LINE__) if definitions
end
def gem(name, *requirements)
- @dependencies.reject! { |dependency| dependency.name == name }
- @dependencies << Dependency.new(name, requirements)
+ @dependencies.add(name, requirements)
end
def group(*names, &block)
- require 'appraisal/group'
-
- group = Group.new(names)
- group.run(&block)
- @groups << group
+ @groups[names] ||= Group.new(names)
+ @groups[names].run(&block)
end
alias_method :groups, :group
def platforms(*names, &block)
- require 'appraisal/platform'
-
- platform = Platform.new(names)
- platform.run(&block)
- @platforms << platform
+ @platforms[names] ||= Platform.new(names)
+ @platforms[names].run(&block)
end
def source(source)
@sources << source
end
@@ -54,20 +52,28 @@
def ruby(ruby_version)
@ruby_version = ruby_version
end
def git(source, options = {}, &block)
- require 'appraisal/git_source'
+ @git_sources[source] ||= GitSource.new(source, options)
+ @git_sources[source].run(&block)
+ end
- git_source = GitSource.new(source, options)
- git_source.run(&block)
- @git_sources << git_source
+ def path(source, options = {}, &block)
+ @path_sources[source] ||= PathSource.new(source, options)
+ @path_sources[source].run(&block)
end
def to_s
- [source_entry, ruby_version_entry, git_sources_entry, dependencies_entry, groups_entry, platforms_entry,
- gemspec_entry].reject{ |s| s.nil? || s.empty? }.join("\n\n").strip
+ [source_entry,
+ ruby_version_entry,
+ git_sources_entry,
+ path_sources_entry,
+ dependencies_entry,
+ groups_entry,
+ platforms_entry,
+ gemspec_entry].reject{ |s| s.nil? || s.empty? }.join("\n\n").strip
end
def dup
gemfile = Gemfile.new
gemfile.run(to_s)
@@ -89,22 +95,26 @@
"ruby #{@ruby_version.inspect}"
end
end
def git_sources_entry
- @git_sources.map(&:to_s).join("\n\n")
+ @git_sources.values.map(&:to_s).join("\n\n")
end
+ def path_sources_entry
+ @path_sources.values.map(&:to_s).join("\n\n")
+ end
+
def dependencies_entry
- dependencies.map(&:to_s).join("\n")
+ @dependencies.to_s
end
def groups_entry
- @groups.map(&:to_s).join("\n\n")
+ @groups.values.map(&:to_s).join("\n\n")
end
def platforms_entry
- @platforms.map(&:to_s).join("\n\n")
+ @platforms.values.map(&:to_s).join("\n\n")
end
def gemspec_entry
@gemspec.to_s
end