From b2a2d9f91b62564e30ab6e77a1347f51f90156f2 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 6 Apr 2010 08:46:57 +1000 Subject: Further expansion into how Bundler loads the gemfile. --- railties/guides/source/initialization.textile | 51 +++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 2d64510c2f..1b76034f82 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -2021,7 +2021,7 @@ This sets up a couple of important things initially. If you specify a gem like t gem 'rails', "2.3.4" -This sets +options+ to be an empty hash, but +version+ to be +"2.3.4"+. TODO: How does one pass options and versions? +This sets +options+ to be an empty hash, but +version+ to be +"2.3.4"+. TODO: How does one pass options and versions at the same time? In the Gemfile for a default Rails project, the first +gem+ line is: @@ -2054,7 +2054,54 @@ This line will check that +options+ contains no deprecated options by using the end -+_normalize_hash+ will convert all the keys in the +opts+ hash to strings. ++_normalize_hash+ will convert all the keys in the +opts+ hash to strings. There is neither a +git+ or a +path+ key in the +opts+ hash so the next couple of lines are ignored, then the +source+ and +group+ keys are set up. + +TODO: Maybe it is best to cover what would happen in the case these lines did exist? + +The next line goes about defining a dependency for this gem: + + + @dependencies << Dependency.new(name, version, options) + + +This class is defined like this: + + + module Bundler + class Dependency < Gem::Dependency + attr_reader :autorequire + attr_reader :groups + + def initialize(name, version, options = {}, &blk) + super(name, version) + + @autorequire = nil + @groups = Array(options["group"] || :default).map { |g| g.to_sym } + @source = options["source"] + + if options.key?('require') + @autorequire = Array(options['require'] || []) + end + end + end + end + + +The +initialize+ method in +Gem::Dependency+ is defined: + + + def initialize(name, version_requirements, type=:runtime) + @name = name + unless TYPES.include? type + raise ArgumentError, "Valid types are #{TYPES.inspect}, not #{@type.inspect}" + end + @type = type + @version_requirements = Gem::Requirement.create version_requirements + @version_requirement = nil # Avoid warnings. + end + + + -- cgit v1.2.3