Class: Blockbuster::Comparator
- Inherits:
-
Object
- Object
- Blockbuster::Comparator
- Includes:
- FileHelpers, OutputHelpers
- Defined in:
- lib/blockbuster/comparator.rb
Overview
Data store for files, sources, states, and checksums
Constant Summary collapse
- CONTENT =
'content'.freeze
- SOURCE =
'source'.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#current_delta_files ⇒ Object
readonly
Returns the value of attribute current_delta_files.
-
#deleted ⇒ Object
readonly
Returns the value of attribute deleted.
-
#edited ⇒ Object
readonly
Returns the value of attribute edited.
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
Instance Method Summary collapse
- #add(key, value, source) ⇒ Object
- #any_deleted? ⇒ Boolean
- #compare(key, new_digest) ⇒ Object
- #delete(key) ⇒ Object
- #edited?(file) ⇒ Boolean
-
#initialize(configuration) ⇒ Comparator
constructor
A new instance of Comparator.
- #keys ⇒ Object
- #present? ⇒ Boolean
-
#rewind?(files) ⇒ Boolean
rubocop:disable Metrics/AbcSize.
- #store_current_delta_files ⇒ Object
Methods included from OutputHelpers
Methods included from FileHelpers
Constructor Details
#initialize(configuration) ⇒ Comparator
Returns a new instance of Comparator.
12 13 14 15 16 17 18 |
# File 'lib/blockbuster/comparator.rb', line 12 def initialize(configuration) @configuration = configuration @inventory = {} @edited = [] @current_delta_files = [] @deleted = [] end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/blockbuster/comparator.rb', line 10 def configuration @configuration end |
#current_delta_files ⇒ Object (readonly)
Returns the value of attribute current_delta_files.
10 11 12 |
# File 'lib/blockbuster/comparator.rb', line 10 def current_delta_files @current_delta_files end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
10 11 12 |
# File 'lib/blockbuster/comparator.rb', line 10 def deleted @deleted end |
#edited ⇒ Object (readonly)
Returns the value of attribute edited.
10 11 12 |
# File 'lib/blockbuster/comparator.rb', line 10 def edited @edited end |
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
10 11 12 |
# File 'lib/blockbuster/comparator.rb', line 10 def inventory @inventory end |
Instance Method Details
#add(key, value, source) ⇒ Object
20 21 22 |
# File 'lib/blockbuster/comparator.rb', line 20 def add(key, value, source) inventory[key] = { CONTENT => value, SOURCE => source } end |
#any_deleted? ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/blockbuster/comparator.rb', line 78 def any_deleted? if configuration.deltas_disabled? && !@deleted.empty? silent_puts "Cassettes deleted: #{@deleted}" return true elsif configuration.deltas_enabled? && !(current_delta_files & @deleted).empty? silent_puts "Cassettes deleted: #{@deleted}" return true end false end |
#compare(key, new_digest) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/blockbuster/comparator.rb', line 47 def compare(key, new_digest) digest = inventory[key] if digest.nil? silent_puts "New cassette: #{key}" return true elsif digest[CONTENT] != new_digest silent_puts "Cassette changed: #{key}" return true end end |
#delete(key) ⇒ Object
24 25 26 |
# File 'lib/blockbuster/comparator.rb', line 24 def delete(key) inventory.delete(key) end |
#edited?(file) ⇒ Boolean
36 37 38 |
# File 'lib/blockbuster/comparator.rb', line 36 def edited?(file) (edited + current_delta_files).include?(file) end |
#keys ⇒ Object
28 29 30 |
# File 'lib/blockbuster/comparator.rb', line 28 def keys inventory.keys end |
#present? ⇒ Boolean
32 33 34 |
# File 'lib/blockbuster/comparator.rb', line 32 def present? !keys.empty? end |
#rewind?(files) ⇒ Boolean
rubocop:disable Metrics/AbcSize
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/blockbuster/comparator.rb', line 59 def rewind?(files) # rubocop:disable Metrics/AbcSize base_files = [] files.each do |file| next unless File.file?(file) key = configuration.key_from_path(file) base_files << key edited << key if compare(key, file_digest(file)) end @deleted = keys - base_files return true if any_deleted? !edited.empty? end |
#store_current_delta_files ⇒ Object
40 41 42 43 44 45 |
# File 'lib/blockbuster/comparator.rb', line 40 def store_current_delta_files inventory.each do |k, v| scrubbed = Blockbuster::Delta.(v[SOURCE]) current_delta_files << k if scrubbed == configuration.current_delta_name end end |