Class: HDOC::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/1hdoc/core/log.rb

Overview

Provides methods for interact with the log file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_path) ⇒ Log

Returns a new instance of Log.

Raises:

  • (Errno::ENOENT)


12
13
14
15
# File 'lib/1hdoc/core/log.rb', line 12

def initialize(log_path)
  @log_path = File.expand_path(log_path)
  raise Errno::ENOENT unless File.exist? log_path
end

Instance Attribute Details

#log_pathObject (readonly)

Returns the value of attribute log_path.



5
6
7
# File 'lib/1hdoc/core/log.rb', line 5

def log_path
  @log_path
end

Class Method Details

.reset(log_path) ⇒ Object



7
8
9
10
# File 'lib/1hdoc/core/log.rb', line 7

def self.reset(log_path)
  log_path = File.expand_path(log_path)
  File.open(log_path, 'w') { |log| log.print '' }
end

Instance Method Details

#append(content) ⇒ Object



17
18
19
# File 'lib/1hdoc/core/log.rb', line 17

def append(content)
  File.open(log_path, 'a') { |log| log.puts content }
end