instance method gem

Ruby on Rails 3.0.20

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

gem(*args)

Adds an entry into Gemfile for the supplied gem. If env is specified, add the gem to the given environment.

Example

gem "rspec", :group => :test
gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
gem "rails", "3.0", :git => "git://github.com/rails/rails"

Parameters

args rest
Source
# File railties/lib/rails/generators/actions.rb, line 52
      def gem(*args)
        options = args.extract_options!
        name, version = args

        # Deal with deprecated options
        { :env => :group, :only => :group,
          :lib => :require, :require_as => :require }.each do |old, new|
          next unless options[old]
          options[new] = options.delete(old)
          ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead"
        end

        # Deal with deprecated source
        if source = options.delete(:source)
          ActiveSupport::Deprecation.warn ":source option in gem is deprecated, use add_source method instead"
          add_source(source)
        end

        # Set the message to be shown in logs. Uses the git repo if one is given,
        # otherwise use name (version).
        parts, message = [ name.inspect ], name
        if version ||= options.delete(:version)
          parts   << version.inspect
          message << " (#{version})"
        end
        message = options[:git] if options[:git]

        log :gemfile, message

        options.each do |option, value|
          parts << ":#{option} => #{value.inspect}"
        end

        in_root do
          append_file "Gemfile", "gem #{parts.join(", ")}\n", :verbose => false
        end
      end

Defined in railties/lib/rails/generators/actions.rb line 52 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::Generators::Actions

Type at least 2 characters to search.

↑↓ navigate · open · esc close