Class: DeployLog::Cache
- Inherits:
-
Object
- Object
- DeployLog::Cache
- Defined in:
- lib/deploy_log/cache.rb
Defined Under Namespace
Classes: FileNotFound
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #contents ⇒ Object
- #create(*args) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(fmt, options = {}) ⇒ Cache
constructor
A new instance of Cache.
- #write_object(pool, message) ⇒ Object
Constructor Details
#initialize(fmt, options = {}) ⇒ Cache
Returns a new instance of Cache.
11 12 13 14 15 16 17 |
# File 'lib/deploy_log/cache.rb', line 11 def initialize(fmt, = {}) fmt ||= 'deploy_%s.log' dir = [:dir] || '/tmp' @repo = [:repo] @file_name_template = "#{dir}/#{fmt}" end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/deploy_log/cache.rb', line 7 def filename @filename end |
Instance Method Details
#contents ⇒ Object
30 31 32 33 34 |
# File 'lib/deploy_log/cache.rb', line 30 def contents raise FileNotFound unless exists? File.read(@filename) end |
#create(*args) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/deploy_log/cache.rb', line 19 def create(*args) hash = Digest::MD5.hexdigest(@repo + args.join('|')) path = FileUtils.touch format(@file_name_template, hash) @filename = path.first end |
#exists? ⇒ Boolean
26 27 28 |
# File 'lib/deploy_log/cache.rb', line 26 def exists? File.exist?(@filename) && !File.size(@filename).zero? end |
#write_object(pool, message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/deploy_log/cache.rb', line 36 def write_object(pool, ) File.open(@filename, 'w+') do |file| pool.each do |pr| line = yield(pr) file.write(line) end file.write "============================================================\n" file.write "#{message}\n" file.write "============================================================\n" end end |