class Shaf::Upgrade::Manifest

Attributes

files[R]
target_version[R]

Public Class Methods

new(**params) click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 8
def initialize(**params)
  @target_version = params[:target_version]
  @files = {}
  @files[:patch] = build_patterns(params[:patches])
  @files[:add] = params[:add] || {}
  @files[:drop] = (params[:drop] || []).map { |d| Regexp.new(d) }
  @files[:regexp] = build_patterns(params[:substitutes])
  @files[:messages] = params[:messages] || []
end

Public Instance Methods

additions() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 22
def additions
  files[:add]
end
drop?(file) click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 46
def drop?(file)
  removals.any? { |pattern| file =~ pattern }
end
messages() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 34
def messages
  files[:messages]
end
patches() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 18
def patches
  files[:patch]
end
patches_for(file) click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 38
def patches_for(file)
  patches.select { |_, pattern| file =~ pattern }.keys
end
regexps() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 30
def regexps
  files[:regexp]
end
regexps_for(file) click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 42
def regexps_for(file)
  regexps.select { |_, pattern| file =~ pattern }.keys
end
removals() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 26
def removals
  files[:drop]
end
stats() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 50
def stats
  {
    additions: additions.size,
    removals: removals.size,
    patches: patches.size,
    regexps: regexps.size,
    messages: messages.size
  }
end
stats_str() click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 60
def stats_str
  "Add: #{additions.size}, " \
    "Del: #{removals.size}, " \
    "Patch: #{patches.size}, " \
    "Regexp: #{regexps.size}, " \
    "Messages: #{messages.size}"
end

Private Instance Methods

build_patterns(patches) click to toggle source
# File lib/shaf/upgrade/manifest.rb, line 70
def build_patterns(patches)
  return {} unless patches
  patches.each_with_object({}) do |(chksum, pattern), hash|
    hash[chksum] = Regexp.new(pattern)
  end
end