Class: BranchableCDNAssets::Manifest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file) ⇒ Manifest

Returns a new instance of Manifest.



8
9
10
11
# File 'lib/branchable_cdn_assets/manifest.rb', line 8

def initialize source_file
  @source_file = source_file
  @file_set    = File.exists?(source_file) ? read_source_file : Set.new
end

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set.



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

def file_set
  @file_set
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



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

def source_file
  @source_file
end

Instance Method Details

#filesArray

list files set as an Array

Returns:

  • (Array)


15
16
17
# File 'lib/branchable_cdn_assets/manifest.rb', line 15

def files
  file_set.to_a
end

#merge_files(new_files) ⇒ Set

add new files to the manifest set

Parameters:

  • new_files (Array)

Returns:

  • (Set)


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

def merge_files new_files
  file_set.merge Array(new_files)
end

#remove_files(files_to_remove) ⇒ Set

remove a set of files from the manifest

Parameters:

  • files_to_remove (Array)

Returns:

  • (Set)


29
30
31
# File 'lib/branchable_cdn_assets/manifest.rb', line 29

def remove_files files_to_remove
  file_set.subtract Array(files_to_remove)
end

#update_source_file!Void

updates the manifest file with the most recent set of files

Returns:

  • (Void)


36
37
38
39
40
41
42
# File 'lib/branchable_cdn_assets/manifest.rb', line 36

def update_source_file!
  destroy! && return if file_set.empty?

  File.open( source_file, 'w' ) do |file|
    file.write manifest_content
  end
end