rkh-bundler 1.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/.gitignore +22 -0
  2. data/.travis.yml +42 -0
  3. data/CHANGELOG.md +1105 -0
  4. data/ISSUES.md +67 -0
  5. data/LICENSE +23 -0
  6. data/README.md +31 -0
  7. data/Rakefile +208 -0
  8. data/UPGRADING.md +103 -0
  9. data/bin/bundle +31 -0
  10. data/bundler.gemspec +31 -0
  11. data/lib/bundler.rb +353 -0
  12. data/lib/bundler/capistrano.rb +11 -0
  13. data/lib/bundler/cli.rb +693 -0
  14. data/lib/bundler/definition.rb +568 -0
  15. data/lib/bundler/dep_proxy.rb +43 -0
  16. data/lib/bundler/dependency.rb +134 -0
  17. data/lib/bundler/deployment.rb +58 -0
  18. data/lib/bundler/dsl.rb +256 -0
  19. data/lib/bundler/endpoint_specification.rb +78 -0
  20. data/lib/bundler/environment.rb +47 -0
  21. data/lib/bundler/fetcher.rb +225 -0
  22. data/lib/bundler/gem_helper.rb +162 -0
  23. data/lib/bundler/gem_helpers.rb +23 -0
  24. data/lib/bundler/gem_installer.rb +9 -0
  25. data/lib/bundler/gem_tasks.rb +2 -0
  26. data/lib/bundler/graph.rb +148 -0
  27. data/lib/bundler/index.rb +187 -0
  28. data/lib/bundler/installer.rb +190 -0
  29. data/lib/bundler/lazy_specification.rb +79 -0
  30. data/lib/bundler/lockfile_parser.rb +127 -0
  31. data/lib/bundler/match_platform.rb +13 -0
  32. data/lib/bundler/psyched_yaml.rb +15 -0
  33. data/lib/bundler/remote_specification.rb +57 -0
  34. data/lib/bundler/resolver.rb +486 -0
  35. data/lib/bundler/ruby_version.rb +94 -0
  36. data/lib/bundler/rubygems_ext.rb +153 -0
  37. data/lib/bundler/rubygems_integration.rb +394 -0
  38. data/lib/bundler/runtime.rb +233 -0
  39. data/lib/bundler/settings.rb +128 -0
  40. data/lib/bundler/setup.rb +23 -0
  41. data/lib/bundler/shared_helpers.rb +71 -0
  42. data/lib/bundler/source.rb +869 -0
  43. data/lib/bundler/spec_set.rb +137 -0
  44. data/lib/bundler/templates/Executable +16 -0
  45. data/lib/bundler/templates/Executable.standalone +12 -0
  46. data/lib/bundler/templates/Gemfile +4 -0
  47. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  48. data/lib/bundler/templates/newgem/LICENSE.tt +22 -0
  49. data/lib/bundler/templates/newgem/README.md.tt +29 -0
  50. data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
  51. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  52. data/lib/bundler/templates/newgem/gitignore.tt +17 -0
  53. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +9 -0
  54. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  55. data/lib/bundler/templates/newgem/newgem.gemspec.tt +17 -0
  56. data/lib/bundler/ui.rb +88 -0
  57. data/lib/bundler/vendor/net/http/faster.rb +27 -0
  58. data/lib/bundler/vendor/net/http/persistent.rb +468 -0
  59. data/lib/bundler/vendor/thor.rb +358 -0
  60. data/lib/bundler/vendor/thor/actions.rb +314 -0
  61. data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
  62. data/lib/bundler/vendor/thor/actions/create_link.rb +57 -0
  63. data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
  64. data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
  65. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +270 -0
  66. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +109 -0
  67. data/lib/bundler/vendor/thor/base.rb +576 -0
  68. data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
  69. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  70. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
  71. data/lib/bundler/vendor/thor/error.rb +30 -0
  72. data/lib/bundler/vendor/thor/group.rb +273 -0
  73. data/lib/bundler/vendor/thor/invocation.rb +168 -0
  74. data/lib/bundler/vendor/thor/parser.rb +4 -0
  75. data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
  76. data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
  77. data/lib/bundler/vendor/thor/parser/option.rb +120 -0
  78. data/lib/bundler/vendor/thor/parser/options.rb +172 -0
  79. data/lib/bundler/vendor/thor/rake_compat.rb +66 -0
  80. data/lib/bundler/vendor/thor/runner.rb +309 -0
  81. data/lib/bundler/vendor/thor/shell.rb +88 -0
  82. data/lib/bundler/vendor/thor/shell/basic.rb +302 -0
  83. data/lib/bundler/vendor/thor/shell/color.rb +108 -0
  84. data/lib/bundler/vendor/thor/shell/html.rb +121 -0
  85. data/lib/bundler/vendor/thor/task.rb +113 -0
  86. data/lib/bundler/vendor/thor/util.rb +229 -0
  87. data/lib/bundler/vendor/thor/version.rb +3 -0
  88. data/lib/bundler/vendored_thor.rb +7 -0
  89. data/lib/bundler/version.rb +6 -0
  90. data/lib/bundler/vlad.rb +11 -0
  91. data/man/bundle-config.ronn +130 -0
  92. data/man/bundle-exec.ronn +111 -0
  93. data/man/bundle-install.ronn +335 -0
  94. data/man/bundle-package.ronn +59 -0
  95. data/man/bundle-update.ronn +176 -0
  96. data/man/bundle.ronn +83 -0
  97. data/man/gemfile.5.ronn +324 -0
  98. data/man/index.txt +6 -0
  99. data/spec/bundler/dsl_spec.rb +48 -0
  100. data/spec/bundler/gem_helper_spec.rb +174 -0
  101. data/spec/bundler/source_spec.rb +25 -0
  102. data/spec/cache/gems_spec.rb +239 -0
  103. data/spec/cache/git_spec.rb +124 -0
  104. data/spec/cache/path_spec.rb +103 -0
  105. data/spec/cache/platform_spec.rb +57 -0
  106. data/spec/install/deploy_spec.rb +211 -0
  107. data/spec/install/gems/c_ext_spec.rb +48 -0
  108. data/spec/install/gems/dependency_api_spec.rb +402 -0
  109. data/spec/install/gems/env_spec.rb +107 -0
  110. data/spec/install/gems/flex_spec.rb +313 -0
  111. data/spec/install/gems/groups_spec.rb +268 -0
  112. data/spec/install/gems/packed_spec.rb +84 -0
  113. data/spec/install/gems/platform_spec.rb +208 -0
  114. data/spec/install/gems/post_install_spec.rb +47 -0
  115. data/spec/install/gems/resolving_spec.rb +72 -0
  116. data/spec/install/gems/simple_case_spec.rb +814 -0
  117. data/spec/install/gems/standalone_spec.rb +260 -0
  118. data/spec/install/gems/sudo_spec.rb +74 -0
  119. data/spec/install/gems/win32_spec.rb +26 -0
  120. data/spec/install/gemspec_spec.rb +170 -0
  121. data/spec/install/git_spec.rb +796 -0
  122. data/spec/install/invalid_spec.rb +35 -0
  123. data/spec/install/path_spec.rb +405 -0
  124. data/spec/install/upgrade_spec.rb +26 -0
  125. data/spec/lock/git_spec.rb +35 -0
  126. data/spec/lock/lockfile_spec.rb +809 -0
  127. data/spec/other/check_spec.rb +265 -0
  128. data/spec/other/clean_spec.rb +492 -0
  129. data/spec/other/config_spec.rb +138 -0
  130. data/spec/other/console_spec.rb +54 -0
  131. data/spec/other/exec_spec.rb +229 -0
  132. data/spec/other/ext_spec.rb +37 -0
  133. data/spec/other/help_spec.rb +39 -0
  134. data/spec/other/init_spec.rb +40 -0
  135. data/spec/other/newgem_spec.rb +87 -0
  136. data/spec/other/open_spec.rb +35 -0
  137. data/spec/other/outdated_spec.rb +93 -0
  138. data/spec/other/platform_spec.rb +881 -0
  139. data/spec/other/show_spec.rb +88 -0
  140. data/spec/quality_spec.rb +62 -0
  141. data/spec/realworld/edgecases_spec.rb +177 -0
  142. data/spec/resolver/basic_spec.rb +20 -0
  143. data/spec/resolver/platform_spec.rb +82 -0
  144. data/spec/runtime/executable_spec.rb +120 -0
  145. data/spec/runtime/load_spec.rb +107 -0
  146. data/spec/runtime/platform_spec.rb +90 -0
  147. data/spec/runtime/require_spec.rb +261 -0
  148. data/spec/runtime/setup_spec.rb +755 -0
  149. data/spec/runtime/with_clean_env_spec.rb +80 -0
  150. data/spec/spec_helper.rb +98 -0
  151. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  152. data/spec/support/artifice/endpoint.rb +54 -0
  153. data/spec/support/artifice/endpoint_500.rb +37 -0
  154. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  155. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  156. data/spec/support/artifice/endpoint_extra.rb +27 -0
  157. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  158. data/spec/support/artifice/endpoint_fallback.rb +18 -0
  159. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  160. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  161. data/spec/support/builders.rb +604 -0
  162. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  163. data/spec/support/fakeweb/windows.rb +23 -0
  164. data/spec/support/helpers.rb +317 -0
  165. data/spec/support/indexes.rb +112 -0
  166. data/spec/support/matchers.rb +77 -0
  167. data/spec/support/path.rb +73 -0
  168. data/spec/support/platforms.rb +86 -0
  169. data/spec/support/ruby_ext.rb +20 -0
  170. data/spec/support/rubygems_ext.rb +37 -0
  171. data/spec/support/rubygems_hax/platform.rb +22 -0
  172. data/spec/support/sudo.rb +21 -0
  173. data/spec/update/gems_spec.rb +134 -0
  174. data/spec/update/git_spec.rb +196 -0
  175. data/spec/update/source_spec.rb +51 -0
  176. metadata +338 -0
@@ -0,0 +1,43 @@
1
+ module Bundler
2
+ class DepProxy
3
+
4
+ attr_reader :required_by, :__platform, :dep
5
+
6
+ def initialize(dep, platform)
7
+ @dep, @__platform, @required_by = dep, platform, []
8
+ end
9
+
10
+ def hash
11
+ @hash ||= dep.hash
12
+ end
13
+
14
+ def ==(o)
15
+ dep == o.dep && __platform == o.__platform
16
+ end
17
+
18
+ alias eql? ==
19
+
20
+ def type
21
+ @dep.type
22
+ end
23
+
24
+ def name
25
+ @dep.name
26
+ end
27
+
28
+ def requirement
29
+ @dep.requirement
30
+ end
31
+
32
+ def to_s
33
+ "#{name} (#{requirement}) #{__platform}"
34
+ end
35
+
36
+ private
37
+
38
+ def method_missing(*args)
39
+ @dep.send(*args)
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,134 @@
1
+ require 'rubygems/dependency'
2
+ require 'bundler/shared_helpers'
3
+ require 'bundler/rubygems_ext'
4
+
5
+ module Bundler
6
+ class Dependency < Gem::Dependency
7
+ attr_reader :autorequire
8
+ attr_reader :groups
9
+ attr_reader :platforms
10
+
11
+ PLATFORM_MAP = {
12
+ :ruby => Gem::Platform::RUBY,
13
+ :ruby_18 => Gem::Platform::RUBY,
14
+ :ruby_19 => Gem::Platform::RUBY,
15
+ :mri => Gem::Platform::RUBY,
16
+ :mri_18 => Gem::Platform::RUBY,
17
+ :mri_19 => Gem::Platform::RUBY,
18
+ :rbx => Gem::Platform::RUBY,
19
+ :jruby => Gem::Platform::JAVA,
20
+ :mswin => Gem::Platform::MSWIN,
21
+ :mingw => Gem::Platform::MINGW,
22
+ :mingw_18 => Gem::Platform::MINGW,
23
+ :mingw_19 => Gem::Platform::MINGW
24
+ }.freeze
25
+
26
+ def initialize(name, version, options = {}, &blk)
27
+ type = options["type"] || :runtime
28
+ super(name, version, type)
29
+
30
+ @autorequire = nil
31
+ @groups = Array(options["group"] || :default).map { |g| g.to_sym }
32
+ @source = options["source"]
33
+ @platforms = Array(options["platforms"])
34
+ @env = options["env"]
35
+
36
+ if options.key?('require')
37
+ @autorequire = Array(options['require'] || [])
38
+ end
39
+ end
40
+
41
+ def gem_platforms(valid_platforms)
42
+ return valid_platforms if @platforms.empty?
43
+
44
+ platforms = []
45
+ @platforms.each do |p|
46
+ platform = PLATFORM_MAP[p]
47
+ next unless valid_platforms.include?(platform)
48
+ platforms |= [platform]
49
+ end
50
+ platforms
51
+ end
52
+
53
+ def should_include?
54
+ current_env? && current_platform?
55
+ end
56
+
57
+ def current_env?
58
+ return true unless @env
59
+ if Hash === @env
60
+ @env.all? do |key, val|
61
+ ENV[key.to_s] && (String === val ? ENV[key.to_s] == val : ENV[key.to_s] =~ val)
62
+ end
63
+ else
64
+ ENV[@env.to_s]
65
+ end
66
+ end
67
+
68
+ def current_platform?
69
+ return true if @platforms.empty?
70
+ @platforms.any? { |p| send("#{p}?") }
71
+ end
72
+
73
+ def to_lock
74
+ out = super
75
+ out << '!' if source
76
+ out << "\n"
77
+ end
78
+
79
+ private
80
+
81
+ def ruby?
82
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev")
83
+ end
84
+
85
+ def ruby_18?
86
+ ruby? && RUBY_VERSION < "1.9"
87
+ end
88
+
89
+ def ruby_19?
90
+ ruby? && RUBY_VERSION >= "1.9" && RUBY_VERSION < "2.0"
91
+ end
92
+
93
+ def mri?
94
+ !mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
95
+ end
96
+
97
+ def mri_18?
98
+ mri? && RUBY_VERSION < "1.9"
99
+ end
100
+
101
+ def mri_19?
102
+ mri? && RUBY_VERSION >= "1.9" && RUBY_VERSION < "2.0"
103
+ end
104
+
105
+ def rbx?
106
+ ruby? && defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
107
+ end
108
+
109
+ def jruby?
110
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
111
+ end
112
+
113
+ def maglev?
114
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "maglev"
115
+ end
116
+
117
+ def mswin?
118
+ Bundler::WINDOWS
119
+ end
120
+
121
+ def mingw?
122
+ Bundler::WINDOWS && Gem::Platform.local.os == "mingw32"
123
+ end
124
+
125
+ def mingw_18?
126
+ mingw? && RUBY_VERSION < "1.9"
127
+ end
128
+
129
+ def mingw_19?
130
+ mingw? && RUBY_VERSION >= "1.9"
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,58 @@
1
+ module Bundler
2
+ class Deployment
3
+ def self.define_task(context, task_method = :task, opts = {})
4
+ if defined?(Capistrano) && context.is_a?(Capistrano::Configuration)
5
+ context_name = "capistrano"
6
+ role_default = "{:except => {:no_release => true}}"
7
+ error_type = ::Capistrano::CommandError
8
+ else
9
+ context_name = "vlad"
10
+ role_default = "[:app]"
11
+ error_type = ::Rake::CommandFailedError
12
+ end
13
+
14
+ roles = context.fetch(:bundle_roles, false)
15
+ opts[:roles] = roles if roles
16
+
17
+ context.send :namespace, :bundle do
18
+ send :desc, <<-DESC
19
+ Install the current Bundler environment. By default, gems will be \
20
+ installed to the shared/bundle path. Gems in the development and \
21
+ test group will not be installed. The install command is executed \
22
+ with the --deployment and --quiet flags. If the bundle cmd cannot \
23
+ be found then you can override the bundle_cmd variable to specifiy \
24
+ which one it should use.
25
+
26
+ You can override any of these defaults by setting the variables shown below.
27
+
28
+ N.B. bundle_roles must be defined before you require 'bundler/#{context_name}' \
29
+ in your deploy.rb file.
30
+
31
+ set :bundle_gemfile, "Gemfile"
32
+ set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
33
+ set :bundle_flags, "--deployment --quiet"
34
+ set :bundle_without, [:development, :test]
35
+ set :bundle_cmd, "bundle" # e.g. "/opt/ruby/bin/bundle"
36
+ set :bundle_roles, #{role_default} # e.g. [:app, :batch]
37
+ DESC
38
+ send task_method, :install, opts do
39
+ bundle_cmd = context.fetch(:bundle_cmd, "bundle")
40
+ bundle_flags = context.fetch(:bundle_flags, "--deployment --quiet")
41
+ bundle_dir = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), 'bundle'))
42
+ bundle_gemfile = context.fetch(:bundle_gemfile, "Gemfile")
43
+ bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact
44
+ current_release = context.fetch(:current_release)
45
+ if current_release.to_s.empty?
46
+ raise error_type.new("Cannot detect current release path - make sure you have deployed at least once.")
47
+ end
48
+ args = ["--gemfile #{File.join(current_release, bundle_gemfile)}"]
49
+ args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
50
+ args << bundle_flags.to_s
51
+ args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
52
+
53
+ run "cd #{current_release} && #{bundle_cmd} install #{args.join(' ')}"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,256 @@
1
+ require 'bundler/dependency'
2
+
3
+ module Bundler
4
+ class Dsl
5
+ def self.evaluate(gemfile, lockfile, unlock)
6
+ builder = new
7
+ builder.eval_gemfile(gemfile)
8
+ builder.to_definition(lockfile, unlock)
9
+ rescue ScriptError, RegexpError, NameError, ArgumentError => e
10
+ e.backtrace[0] = "#{e.backtrace[0]}: #{e.message} (#{e.class})"
11
+ Bundler.ui.info e.backtrace.join("\n ")
12
+ raise GemfileError, "There was an error in your Gemfile," \
13
+ " and Bundler cannot continue."
14
+ end
15
+
16
+ VALID_PLATFORMS = Bundler::Dependency::PLATFORM_MAP.keys.freeze
17
+
18
+ attr_accessor :dependencies
19
+
20
+ def initialize
21
+ @rubygems_source = Source::Rubygems.new
22
+ @source = nil
23
+ @sources = []
24
+ @dependencies = []
25
+ @groups = []
26
+ @platforms = []
27
+ @env = nil
28
+ @ruby_version = nil
29
+ end
30
+
31
+ def eval_gemfile(gemfile)
32
+ instance_eval(Bundler.read_file(gemfile.to_s), gemfile.to_s, 1)
33
+ rescue SyntaxError => e
34
+ bt = e.message.split("\n")[1..-1]
35
+ raise GemfileError, ["Gemfile syntax error:", *bt].join("\n")
36
+ end
37
+
38
+ def gemspec(opts = nil)
39
+ path = opts && opts[:path] || '.'
40
+ name = opts && opts[:name] || '{,*}'
41
+ development_group = opts && opts[:development_group] || :development
42
+ path = File.expand_path(path, Bundler.default_gemfile.dirname)
43
+ gemspecs = Dir[File.join(path, "#{name}.gemspec")]
44
+
45
+ case gemspecs.size
46
+ when 1
47
+ spec = Bundler.load_gemspec(gemspecs.first)
48
+ raise InvalidOption, "There was an error loading the gemspec at #{gemspecs.first}." unless spec
49
+ gem spec.name, :path => path
50
+ group(development_group) do
51
+ spec.development_dependencies.each do |dep|
52
+ gem dep.name, *(dep.requirement.as_list + [:type => :development])
53
+ end
54
+ end
55
+ when 0
56
+ raise InvalidOption, "There are no gemspecs at #{path}."
57
+ else
58
+ raise InvalidOption, "There are multiple gemspecs at #{path}. Please use the :name option to specify which one."
59
+ end
60
+ end
61
+
62
+ def gem(name, *args)
63
+ if name.is_a?(Symbol)
64
+ raise GemfileError, %{You need to specify gem names as Strings. Use 'gem "#{name.to_s}"' instead.}
65
+ end
66
+
67
+ options = Hash === args.last ? args.pop : {}
68
+ version = args || [">= 0"]
69
+
70
+ _normalize_options(name, version, options)
71
+
72
+ dep = Dependency.new(name, version, options)
73
+
74
+ # if there's already a dependency with this name we try to prefer one
75
+ if current = @dependencies.find { |d| d.name == dep.name }
76
+ if current.requirement != dep.requirement
77
+ if current.type == :development
78
+ @dependencies.delete current
79
+ elsif dep.type == :development
80
+ return
81
+ else
82
+ raise DslError, "You cannot specify the same gem twice with different version requirements. " \
83
+ "You specified: #{current.name} (#{current.requirement}) and " \
84
+ "#{dep.name} (#{dep.requirement})"
85
+ end
86
+ end
87
+
88
+ if current.source != dep.source
89
+ if current.type == :development
90
+ @dependencies.delete current
91
+ elsif dep.type == :development
92
+ return
93
+ else
94
+ raise DslError, "You cannot specify the same gem twice coming from different sources. You " \
95
+ "specified that #{dep.name} (#{dep.requirement}) should come from " \
96
+ "#{current.source || 'an unspecfied source'} and #{dep.source}"
97
+ end
98
+ end
99
+ end
100
+
101
+ @dependencies << dep
102
+ end
103
+
104
+ def source(source, options = {})
105
+ case source
106
+ when :gemcutter, :rubygems, :rubyforge then
107
+ @rubygems_source.add_remote "http://rubygems.org"
108
+ return
109
+ when String
110
+ @rubygems_source.add_remote source
111
+ return
112
+ else
113
+ @source = source
114
+ if options[:prepend]
115
+ @sources = [@source] | @sources
116
+ else
117
+ @sources = @sources | [@source]
118
+ end
119
+
120
+ yield if block_given?
121
+ return @source
122
+ end
123
+ ensure
124
+ @source = nil
125
+ end
126
+
127
+ def path(path, options = {}, source_options = {}, &blk)
128
+ source Source::Path.new(_normalize_hash(options).merge("path" => Pathname.new(path))), source_options, &blk
129
+ end
130
+
131
+ def git(uri, options = {}, source_options = {}, &blk)
132
+ unless block_given?
133
+ msg = "You can no longer specify a git source by itself. Instead, \n" \
134
+ "either use the :git option on a gem, or specify the gems that \n" \
135
+ "bundler should find in the git source by passing a block to \n" \
136
+ "the git method, like: \n\n" \
137
+ " git 'git://github.com/rails/rails.git' do\n" \
138
+ " gem 'rails'\n" \
139
+ " end"
140
+ raise DeprecatedError, msg
141
+ end
142
+
143
+ source Source::Git.new(_normalize_hash(options).merge("uri" => uri)), source_options, &blk
144
+ end
145
+
146
+ def to_definition(lockfile, unlock)
147
+ @sources << @rubygems_source unless @sources.include?(@rubygems_source)
148
+ Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version)
149
+ end
150
+
151
+ def group(*args, &blk)
152
+ @groups.concat args
153
+ yield
154
+ ensure
155
+ args.each { @groups.pop }
156
+ end
157
+
158
+ def platforms(*platforms)
159
+ @platforms.concat platforms
160
+ yield
161
+ ensure
162
+ platforms.each { @platforms.pop }
163
+ end
164
+ alias_method :platform, :platforms
165
+
166
+ def env(name)
167
+ @env, old = name, @env
168
+ yield
169
+ ensure
170
+ @env = old
171
+ end
172
+
173
+ def ruby(ruby_version, options = {})
174
+ raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
175
+ raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
176
+
177
+ raise GemfileError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
178
+ @ruby_version = RubyVersion.new(ruby_version, options[:engine], options[:engine_version])
179
+ end
180
+
181
+ def method_missing(name, *args)
182
+ location = caller[0].split(':')[0..1].join(':')
183
+ raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile\n" \
184
+ " from #{location}"
185
+ end
186
+
187
+ private
188
+
189
+ def _normalize_hash(opts)
190
+ # Cannot modify a hash during an iteration in 1.9
191
+ opts.keys.each do |k|
192
+ next if String === k
193
+ v = opts[k]
194
+ opts.delete(k)
195
+ opts[k.to_s] = v
196
+ end
197
+ opts
198
+ end
199
+
200
+ def _normalize_options(name, version, opts)
201
+ _normalize_hash(opts)
202
+
203
+ valid_keys = %w(group groups git github path name branch ref tag require submodules platform platforms type)
204
+ invalid_keys = opts.keys - valid_keys
205
+ if invalid_keys.any?
206
+ plural = invalid_keys.size > 1
207
+ message = "You passed #{invalid_keys.map{|k| ':'+k }.join(", ")} "
208
+ if plural
209
+ message << "as options for gem '#{name}', but they are invalid."
210
+ else
211
+ message << "as an option for gem '#{name}', but it is invalid."
212
+ end
213
+
214
+ message << " Valid options are: #{valid_keys.join(", ")}"
215
+ raise InvalidOption, message
216
+ end
217
+
218
+ groups = @groups.dup
219
+ opts["group"] = opts.delete("groups") || opts["group"]
220
+ groups.concat Array(opts.delete("group"))
221
+ groups = [:default] if groups.empty?
222
+
223
+ platforms = @platforms.dup
224
+ opts["platforms"] = opts["platform"] || opts["platforms"]
225
+ platforms.concat Array(opts.delete("platforms"))
226
+ platforms.map! { |p| p.to_sym }
227
+ platforms.each do |p|
228
+ next if VALID_PLATFORMS.include?(p)
229
+ raise DslError, "`#{p}` is not a valid platform. The available options are: #{VALID_PLATFORMS.inspect}"
230
+ end
231
+
232
+ if github = opts.delete("github")
233
+ github = "#{github}/#{github}" unless github.include?("/")
234
+ opts["git"] = "git://github.com/#{github}.git"
235
+ end
236
+
237
+ ["git", "path"].each do |type|
238
+ if param = opts[type]
239
+ if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/
240
+ options = opts.merge("name" => name, "version" => $1)
241
+ else
242
+ options = opts.dup
243
+ end
244
+ source = send(type, param, options, :prepend => true) {}
245
+ opts["source"] = source
246
+ end
247
+ end
248
+
249
+ opts["source"] ||= @source
250
+ opts["env"] ||= @env
251
+ opts["platforms"] = platforms.dup
252
+ opts["group"] = groups
253
+ end
254
+
255
+ end
256
+ end