Module: StateInspector::Observers::SessionLoggerObserver
- Extended by:
- Observer
- Defined in:
- lib/state_inspector/observers/session_logger_observer.rb
Class Method Summary
collapse
Methods included from Observer
display, purge, update, values
Class Method Details
30
31
32
33
34
35
36
|
# File 'lib/state_inspector/observers/session_logger_observer.rb', line 30
def display
if @file
File.open(@file, File::RDONLY) {|f| f.read }
else
""
end
end
|
25
26
27
28
|
# File 'lib/state_inspector/observers/session_logger_observer.rb', line 25
def file= f
warn("Warning! Log file #{@file} was already set!") if @file
@file = f
end
|
52
53
54
55
|
# File 'lib/state_inspector/observers/session_logger_observer.rb', line 52
def purge
File.delete(@file) if File.exist? @file
@file = nil
end
|
.update(*values) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/state_inspector/observers/session_logger_observer.rb', line 10
def update *values
@file ||= File.join(
'log', 'state_inspector',
['session', Time.now.to_i, 'log'].join('.')
)
FileUtils.mkdir_p File.dirname(@file)
File.open(@file, File::WRONLY | File::APPEND | File::CREAT) do |file|
logger = Logger.new(file)
logger << values.
map(&value_mapper).
join(splitter)
logger << "\n"
end
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/state_inspector/observers/session_logger_observer.rb', line 38
def values
if @file
File.open(@file, File::RDONLY) {|f| f.readlines}.map(&:chomp).map do |line|
if line.empty?
nil
else
line.split(splitter).map(&value_mapper)
end
end.compact
else
[]
end
end
|