Class: Nydp::ImageStore

Inherits:
Object show all
Defined in:
lib/nydp/image_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store = nil) ⇒ ImageStore

Returns a new instance of ImageStore.



7
8
9
10
# File 'lib/nydp/image_store.rb', line 7

def initialize store=nil
  @store = store
  FileUtils.mkdir_p(store, mode: 0775) if store
end

Instance Attribute Details

#store(id, image) ⇒ Object

Returns the value of attribute store.



5
6
7
# File 'lib/nydp/image_store.rb', line 5

def store
  @store
end

Instance Method Details

#digestObject



12
# File 'lib/nydp/image_store.rb', line 12

def digest          ; Digest::MD5.hexdigest(Nydp.all_files.map { |f| File.read f }.join) ; end

#file_name(id) ⇒ Object



13
# File 'lib/nydp/image_store.rb', line 13

def file_name    id ; File.join @store, "#{id}.nydp_image"                               ; end

#generate(id) ⇒ Object



17
# File 'lib/nydp/image_store.rb', line 17

def generate     id ; Marshal.dump(::Nydp.build_nydp).tap { |im| store id, im }          ; end

#getObject



19
# File 'lib/nydp/image_store.rb', line 19

def get             ; Marshal.load(@image ||= resurrect(digest))                         ; end

#load(id) ⇒ Object



15
# File 'lib/nydp/image_store.rb', line 15

def load         id ; load?(file_name id) if @store                                      ; end

#load?(fname) ⇒ Boolean

Returns:

  • (Boolean)


14
# File 'lib/nydp/image_store.rb', line 14

def load?     fname ; File.binread(fname) if File.exists?(fname)                         ; end

#resurrect(id) ⇒ Object



18
# File 'lib/nydp/image_store.rb', line 18

def resurrect    id ; load(id) || generate(id)                                           ; end