instance method
gem
Ruby on Rails 6.1.7.10
Since v3.0.20Signature
gem(*args)
Adds an entry into Gemfile for the supplied gem.
gem "rspec", group: :test gem "technoweenie-restful-authentication", lib: "restful-authentication", source: "http://gems.github.com/" gem "rails", "3.0", git: "https://github.com/rails/rails" gem "RedCloth", ">= 4.1.0", "< 4.2.0"
Parameters
-
argsrest
Source
# File railties/lib/rails/generators/actions.rb, line 21
def gem(*args)
options = args.extract_options!
name, *versions = args
# Set the message to be shown in logs. Uses the git repo if one is given,
# otherwise use name (version).
parts, message = [ quote(name) ], name.dup
if versions = versions.any? ? versions : options.delete(:version)
_versions = Array(versions)
_versions.each do |version|
parts << quote(version)
end
message << " (#{_versions.join(", ")})"
end
message = options[:git] if options[:git]
log :gemfile, message
parts << quote(options) unless options.empty?
in_root do
str = "gem #{parts.join(", ")}"
str = indentation + str
append_file_with_newline "Gemfile", str, verbose: false
end
end
Defined in railties/lib/rails/generators/actions.rb line 21
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Rails::Generators::Actions