Class: CmdLine::CacheFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_dir, args) ⇒ CacheFile

Returns a new instance of CacheFile.



14
15
16
17
18
19
20
# File 'lib/cmdline/cachefile.rb', line 14

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.



11
12
13
# File 'lib/cmdline/cachefile.rb', line 11

def output
  @output
end

#pathnameObject (readonly)

Returns the value of attribute pathname.



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

def pathname
  @pathname
end

Instance Method Details

#readlinesObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/cmdline/cachefile.rb', line 22

def readlines
  if @pathname.exist?
    @output = @pathname.read_file
  else
    cl = CommandLine.new @args
    @output = cl.execute
    @pathname.save_file @output
    @output
  end
end

#to_sObject



33
34
35
# File 'lib/cmdline/cachefile.rb', line 33

def to_s
  @pathname.to_s
end