Class: Shaf::Upgrade::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf/upgrade/manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) ⇒ Manifest

Returns a new instance of Manifest.



8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/shaf/upgrade/manifest.rb', line 6

def files
  @files
end

#target_versionObject (readonly)

Returns the value of attribute target_version.



6
7
8
# File 'lib/shaf/upgrade/manifest.rb', line 6

def target_version
  @target_version
end

Instance Method Details

#additionsObject



22
23
24
# File 'lib/shaf/upgrade/manifest.rb', line 22

def additions
  files[:add]
end

#drop?(file) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/shaf/upgrade/manifest.rb', line 46

def drop?(file)
  removals.any? { |pattern| file =~ pattern }
end

#messagesObject



34
35
36
# File 'lib/shaf/upgrade/manifest.rb', line 34

def messages
  files[:messages]
end

#patchesObject



18
19
20
# File 'lib/shaf/upgrade/manifest.rb', line 18

def patches
  files[:patch]
end

#patches_for(file) ⇒ Object



38
39
40
# File 'lib/shaf/upgrade/manifest.rb', line 38

def patches_for(file)
  patches.select { |_, pattern| file =~ pattern }.keys
end

#regexpsObject



30
31
32
# File 'lib/shaf/upgrade/manifest.rb', line 30

def regexps
  files[:regexp]
end

#regexps_for(file) ⇒ Object



42
43
44
# File 'lib/shaf/upgrade/manifest.rb', line 42

def regexps_for(file)
  regexps.select { |_, pattern| file =~ pattern }.keys
end

#removalsObject



26
27
28
# File 'lib/shaf/upgrade/manifest.rb', line 26

def removals
  files[:drop]
end

#statsObject



50
51
52
53
54
55
56
57
58
# 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_strObject



60
61
62
63
64
65
66
# 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