Class: Bundle::Patch::Config
- Inherits:
-
Object
- Object
- Bundle::Patch::Config
- Defined in:
- lib/bundle/patch/config.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#skip_bundle_install ⇒ Object
readonly
Returns the value of attribute skip_bundle_install.
Class Method Summary collapse
Instance Method Summary collapse
- #allow_update?(from_version, to_version) ⇒ Boolean
-
#initialize(dry_run: false, mode: "patch", skip_bundle_install: false) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(dry_run: false, mode: "patch", skip_bundle_install: false) ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 |
# File 'lib/bundle/patch/config.rb', line 9 def initialize(dry_run: false, mode: "patch", skip_bundle_install: false) @dry_run = dry_run @mode = mode @skip_bundle_install = skip_bundle_install end |
Instance Attribute Details
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
7 8 9 |
# File 'lib/bundle/patch/config.rb', line 7 def dry_run @dry_run end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
7 8 9 |
# File 'lib/bundle/patch/config.rb', line 7 def mode @mode end |
#skip_bundle_install ⇒ Object (readonly)
Returns the value of attribute skip_bundle_install.
7 8 9 |
# File 'lib/bundle/patch/config.rb', line 7 def skip_bundle_install @skip_bundle_install end |
Class Method Details
.from_argv(argv) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bundle/patch/config.rb', line 15 def self.from_argv(argv) = { dry_run: false, skip_bundle_install: false, mode: "patch" } OptionParser.new do |opts| opts. = "Usage: bundle-patch [options]" opts.on("--dry-run", "Print what would be done, but don't change anything") do [:dry_run] = true end opts.on("--skip-bundle-install", "Skip running `bundle install` after patching") do [:skip_bundle_install] = true end opts.on("--mode=MODE", "Update mode: patch (default), minor, or all") do |mode| unless %w[patch minor all].include?(mode) raise OptionParser::InvalidArgument, "Invalid mode: #{mode}" end [:mode] = mode end end.parse!(argv) new(**) end |
Instance Method Details
#allow_update?(from_version, to_version) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bundle/patch/config.rb', line 44 def allow_update?(from_version, to_version) return true if mode == "all" from = Gem::Version.new(from_version) to = Gem::Version.new(to_version) case mode when "patch" same_major?(from, to) && same_minor?(from, to) when "minor" same_major?(from, to) else true end end |