Class: System::CacheFile
- Inherits:
-
Object
- Object
- System::CacheFile
- Includes:
- Logue::Loggable
- Defined in:
- lib/system/command/cachefile.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(cache_dir, args) ⇒ CacheFile
constructor
A new instance of CacheFile.
- #read_file ⇒ Object
- #readlines ⇒ Object
- #save_file ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(cache_dir, args) ⇒ CacheFile
Returns a new instance of CacheFile.
14 15 16 17 18 |
# File 'lib/system/command/cachefile.rb', line 14 def initialize cache_dir, args @args = args @pn = Pathname.new(cache_dir) + (args.join('-').gsub('/', '_slash_') + '.gz') @output = nil end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
12 13 14 |
# File 'lib/system/command/cachefile.rb', line 12 def output @output end |
Instance Method Details
#read_file ⇒ Object
28 29 30 31 32 33 |
# File 'lib/system/command/cachefile.rb', line 28 def read_file Zlib::GzipReader.open(@pn.to_s) do |gz| @output = gz.readlines end @output end |
#readlines ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/system/command/cachefile.rb', line 35 def readlines if @pn.exist? read_file else cl = CommandLine.new @args @output = cl.execute save_file @output end end |
#save_file ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/system/command/cachefile.rb', line 20 def save_file @pn.parent.mkpath unless @pn.parent.exist? @pn.unlink if @pn.exist? Zlib::GzipWriter.open(@pn.to_s) do |gz| gz.puts @output end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/system/command/cachefile.rb', line 46 def to_s @pn.to_s end |