instance method
gem
Ruby on Rails 4.2.9
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: "git://github.com/rails/rails"
Parameters
-
argsrest
Source
# File railties/lib/rails/generators/actions.rb, line 17
def gem(*args)
options = args.extract_options!
name, version = 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
if version ||= options.delete(:version)
parts << quote(version)
message << " (#{version})"
end
message = options[:git] if options[:git]
log :gemfile, message
options.each do |option, value|
parts << "#{option}: #{quote(value)}"
end
in_root do
str = "gem #{parts.join(", ")}"
str = " " + str if @in_group
str = "\n" + str
append_file "Gemfile", str, verbose: false
end
end
Defined in railties/lib/rails/generators/actions.rb line 17
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Rails::Generators::Actions