Class: Command::Cacheable::CacheFile

Inherits:
Object
  • Object
show all
Defined in:
lib/command/cacheable/cachefile.rb

Overview

A file that has a pathname and output $$$ todo: cache error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_dir, args) ⇒ CacheFile

Returns a new instance of CacheFile.



15
16
17
18
19
20
21
# File 'lib/command/cacheable/cachefile.rb', line 15

def initialize cache_dir, args
  @args     = args
  basename  = FileName.new(args).name
  fullname  = Pathname(cache_dir) + basename
  @pathname = GzipPathname.new fullname
  @output   = nil
end

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



12
13
14
# File 'lib/command/cacheable/cachefile.rb', line 12

def output
  @output
end

#pathnameObject (readonly)

Returns the value of attribute pathname.



13
14
15
# File 'lib/command/cacheable/cachefile.rb', line 13

def pathname
  @pathname
end

Instance Method Details

#readObject



23
24
25
# File 'lib/command/cacheable/cachefile.rb', line 23

def read
  @output = @pathname.exist? && @pathname.read_file
end

#save(output) ⇒ Object



27
28
29
# File 'lib/command/cacheable/cachefile.rb', line 27

def save output
  @pathname.save_file output
end

#to_sObject



31
32
33
# File 'lib/command/cacheable/cachefile.rb', line 31

def to_s
  @pathname.to_s
end