Class: BundlerConservativeUpdate::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler_conservative_update.rb

Overview

Decides whether a bundle update invocation should be re-executed with --conservative. Instantiated with injected argv and env so it can be tested without a real Bundler run.

Instance Method Summary collapse

Constructor Details

#initialize(argv:, env:) ⇒ Hook

Returns a new instance of Hook.



43
44
45
46
# File 'lib/bundler_conservative_update.rb', line 43

def initialize(argv:, env:)
  @argv = argv
  @env  = env
end

Instance Method Details

#conservative_argvObject

The original argv with --conservative inserted right after the subcommand, leaving the receiver's argv untouched.



67
68
69
70
71
# File 'lib/bundler_conservative_update.rb', line 67

def conservative_argv
  new_argv = @argv.dup
  new_argv.insert(update_index + 1, "--conservative")
  new_argv
end

#should_inject?Boolean

True when the current command is a bundle update that names a scope to update and has not already stated its own update strategy.

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bundler_conservative_update.rb', line 50

def should_inject?
  index = update_index

  return false if index.nil?
  return false unless @argv[index] == "update"

  args = @argv[(index + 1)..] || []

  return false if skip_flag?(args)
  return false unless scope?(args)
  return false if disabled?

  true
end