Class: DRG::Tasks::ProgessivePinner
- Inherits:
-
Object
- Object
- DRG::Tasks::ProgessivePinner
- Includes:
- Log
- Defined in:
- lib/drg/tasks/progressive_pinner.rb
Instance Attribute Summary collapse
-
#gemfile ⇒ Object
readonly
Returns the value of attribute gemfile.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#updated_gems ⇒ Object
readonly
Returns the value of attribute updated_gems.
-
#versions(name) ⇒ Array
A list of available versions (e.g. [‘1.2.0’, ‘1.1.0’]).
Instance Method Summary collapse
- #higher?(list, other_list) ⇒ Boolean
-
#initialize(type = :patch) ⇒ ProgessivePinner
constructor
A new instance of ProgessivePinner.
- #latest_minor_version(name, current_version) ⇒ Object
- #latest_patch_version(name, current_version) ⇒ Object
- #new_versions(name, current_version) ⇒ Object
- #perform(gem_name = nil) ⇒ Object
- #update(spec) ⇒ Object
- #update_all ⇒ Object
- #update_handler(gem) ⇒ Object
Methods included from Log
Constructor Details
#initialize(type = :patch) ⇒ ProgessivePinner
Returns a new instance of ProgessivePinner.
10 11 12 13 14 15 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 10 def initialize(type = :patch) @type = type @gemfile = Gemfile.new @versions = {} @updated_gems = Set.new end |
Instance Attribute Details
#gemfile ⇒ Object (readonly)
Returns the value of attribute gemfile.
6 7 8 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 6 def gemfile @gemfile end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 6 def type @type end |
#updated_gems ⇒ Object (readonly)
Returns the value of attribute updated_gems.
6 7 8 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 6 def updated_gems @updated_gems end |
#versions(name) ⇒ Array
Returns a list of available versions (e.g. [‘1.2.0’, ‘1.1.0’]).
81 82 83 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 81 def versions(name) @versions[name] ||= `gem query -radn ^#{name}$`.scan(/([\d.]+),/).flatten.uniq end |
Instance Method Details
#higher?(list, other_list) ⇒ Boolean
85 86 87 88 89 90 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 85 def higher?(list, other_list) return true if list[0].to_i > other_list[0].to_i return true if list[1].to_i > other_list[1].to_i return true if list[2].to_i > other_list[2].to_i false end |
#latest_minor_version(name, current_version) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 53 def latest_minor_version(name, current_version) new_versions(name, current_version).select { |version| segments = version.scan(/\d+/) major_version = segments[0].to_i minor_version = segments[1].to_i minor_version > current_version.segments[1] && major_version == current_version.segments[0] }.first end |
#latest_patch_version(name, current_version) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 64 def latest_patch_version(name, current_version) new_versions(name, current_version).select { |version| segments = version.scan(/\d+/) patch_version = segments[-1].to_i minor_version = segments[1].to_i patch_version > current_version.segments[-1] && minor_version == current_version.segments[1] }.first end |
#new_versions(name, current_version) ⇒ Object
75 76 77 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 75 def new_versions(name, current_version) versions(name).select { |version| higher?(version.scan(/\d+/), current_version.segments) } end |
#perform(gem_name = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 17 def perform(gem_name = nil) if gem_name update ::Bundler.locked_gems.specs.find { |spec| spec.name == gem_name } else update_all end gemfile.write if gemfile.saved_lines.any? log %Q(Done.#{' You may want run `bundle update`' if updated_gems.any?}) end |
#update(spec) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 36 def update(spec) gem = gemfile.find_by_name spec.name if gem log %Q[Searching for latest #{type} version of "#{spec.name}" (currently #{spec.version.to_s}) ...] latest_version = public_send("latest_#{type}_version", spec.name, spec.version) if latest_version log "Updating to version #{latest_version}" gemfile.update gem, latest_version updated_gems << gem.name else log %Q(No newer #{type} versions found) end end end |
#update_all ⇒ Object
27 28 29 30 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 27 def update_all log %Q(No gem specified) Updater.new.perform method(:update_handler) end |
#update_handler(gem) ⇒ Object
32 33 34 |
# File 'lib/drg/tasks/progressive_pinner.rb', line 32 def update_handler(gem) update ::Bundler.locked_gems.specs.find { |spec| spec.name == gem.name } end |