instance method
gem
Ruby on Rails 3.0.20
Since v3.0.20Signature
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
-
argsrest
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