method
gem
v2_6_3 -
Show latest stable
- Class:
Bundler::Dsl
gem(name, *args)public
No documentation available.
# File lib/bundler/dsl.rb, line 94
def gem(name, *args)
options = args.last.is_a?(Hash) ? args.pop.dup : {}
options["gemfile"] = @gemfile
version = args || [">= 0"]
normalize_options(name, version, options)
dep = Dependency.new(name, version, options)
# if there's already a dependency with this name we try to prefer one
if current = @dependencies.find {|d| d.name == dep.name }
deleted_dep = @dependencies.delete(current) if current.type == :development
if current.requirement != dep.requirement
unless deleted_dep
return if dep.type == :development
update_prompt = ""
if File.basename(@gemfile) == Injector::INJECTED_GEMS
if dep.requirements_list.include?(">= 0") && !current.requirements_list.include?(">= 0")
update_prompt = ". Gem already added"
else
update_prompt = ". If you want to update the gem version, run `bundle update #{current.name}`"
update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current.requirements_list.include?(">= 0")
end
end
raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" "#{update_prompt}"
end
else
Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" "You should probably keep only one of them.\n" "Remove any duplicate entries and specify the gem only once (per group).\n" "While it's not a problem now, it could cause errors if you change the version of one of them later."
end
if current.source != dep.source
unless deleted_dep
return if dep.type == :development
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" "You specified that #{dep.name} (#{dep.requirement}) should come from " "#{current.source || "an unspecified source"} and #{dep.source}\n"
end
end
end
@dependencies << dep
end