Flowdock
method

gem

Importance_0
v2_6_3 - Show latest stable - 0 notes - Class: Dsl
  • 1_8_6_287
  • 1_8_7_72
  • 1_8_7_330
  • 1_9_1_378
  • 1_9_2_180
  • 1_9_3_125
  • 1_9_3_392
  • 2_1_10
  • 2_2_9
  • 2_4_6
  • 2_5_5
  • 2_6_3 (0)
  • What's this?
gem(name, *args) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# 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
Register or log in to add new notes.