summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorBoggs <hello.boggs@gmail.com>2016-06-16 12:27:23 +0800
committerBoggs <hello.boggs@gmail.com>2016-06-16 12:27:23 +0800
commitbf1de4c1d4b988aaf3305127fbfc3b64bef8aea6 (patch)
tree8c18522a323f38010c0110eef35ccfefe66381be /lib/bundler
parentf59164dee5bd9f84979b23ade5a1c1c7a947696e (diff)
downloadbundler-bf1de4c1d4b988aaf3305127fbfc3b64bef8aea6.tar.gz
Add option to `remove_timestamp` from `Injector` class.
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/inject.rb8
-rw-r--r--lib/bundler/injector.rb11
3 files changed, 13 insertions, 8 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 95be9388a9..90fb481cc1 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -450,7 +450,7 @@ module Bundler
# require "bundler/cli/add"
# Add.new(options, name, version, gems).run
require "bundler/cli/inject"
- Inject.new(options, name, version, gems).run
+ Inject.new(options, name, version, gems, "add").run
end
if Bundler.settings[:plugins]
diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb
index bebc438370..1eeb950f3e 100644
--- a/lib/bundler/cli/inject.rb
+++ b/lib/bundler/cli/inject.rb
@@ -2,12 +2,13 @@
require "bundler/cli/common"
module Bundler
class CLI::Inject
- attr_reader :options, :name, :version, :gems
- def initialize(options, name, version, gems)
+ attr_reader :options, :name, :version, :gems, :command
+ def initialize(options, name, version, gems, command = "inject")
@options = options
@name = name
@version = version || last_version_number
@gems = gems
+ @command = command
end
def run
@@ -21,7 +22,8 @@ module Bundler
deps << Bundler::Dependency.new(gem_name, gem_version)
end
- added = Injector.inject(deps)
+ options = command == "add" ? { remove_timestamp: true } : {}
+ added = Injector.inject(deps, options)
if added.any?
Bundler.ui.confirm "Added to Gemfile:"
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb
index c27e2499ca..33f271399a 100644
--- a/lib/bundler/injector.rb
+++ b/lib/bundler/injector.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
module Bundler
class Injector
- def self.inject(new_deps)
- injector = new(new_deps)
+ def self.inject(new_deps, options = {})
+ injector = new(new_deps, options)
injector.inject(Bundler.default_gemfile, Bundler.default_lockfile)
end
- def initialize(new_deps)
+ def initialize(new_deps, options = {})
@new_deps = new_deps
+ @options = options
end
def inject(gemfile_path, lockfile_path)
@@ -55,7 +56,9 @@ module Bundler
def append_to(gemfile_path)
gemfile_path.open("a") do |f|
f.puts
- f.puts "# Added at #{Time.now} by #{`whoami`.chomp}:"
+ unless !!@options[:remove_timestamp]
+ f.puts "# Added at #{Time.now} by #{`whoami`.chomp}:"
+ end
f.puts new_gem_lines
end
end