Class: ShopifyCLI::Theme::Syncer::Checksums

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/syncer/checksums.rb

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ Checksums

Returns a new instance of Checksums.



7
8
9
10
11
12
13
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 7

def initialize(theme)
  @theme = theme
  @checksum_by_key = {}

  # Mutex used to coordinate changes in the checksums (shared accross `Syncer` threads)
  @checksums_mutex = Mutex.new
end

Instance Method Details

#[](key) ⇒ Object



33
34
35
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 33

def [](key)
  checksum_by_key[key]
end

#[]=(key, value) ⇒ Object



37
38
39
40
41
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 37

def []=(key, value)
  checksums_mutex.synchronize do
    checksum_by_key[key] = value
  end
end

#delete(file) ⇒ Object



23
24
25
26
27
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 23

def delete(file)
  checksums_mutex.synchronize do
    checksum_by_key.delete(to_key(file))
  end
end

#file_has_changed?(file) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 19

def file_has_changed?(file)
  file.checksum != checksum_by_key[file.relative_path]
end

#has?(file) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 15

def has?(file)
  checksum_by_key.key?(to_key(file))
end

#keysObject



29
30
31
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 29

def keys
  checksum_by_key.keys
end

#reject_duplicated_checksums!Object

Generate .liquid asset files are reported twice in checksum: once of generated, once for .liquid. We only keep the .liquid, that’s the one we have on disk.



46
47
48
49
50
# File 'lib/shopify_cli/theme/syncer/checksums.rb', line 46

def reject_duplicated_checksums!
  checksums_mutex.synchronize do
    checksum_by_key.reject! { |key, _| checksum_by_key.key?("#{key}.liquid") }
  end
end