Class: Madeleine::CommandLog
- Inherits:
-
Object
- Object
- Madeleine::CommandLog
- Defined in:
- lib/madeleine.rb
Overview
:nodoc:
Class Method Summary collapse
- .highest_log(directory_name, file_service) ⇒ Object
- .log_file_names(directory_name, file_service) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, file_service) ⇒ CommandLog
constructor
A new instance of CommandLog.
- #store(command) ⇒ Object
Constructor Details
#initialize(path, file_service) ⇒ CommandLog
Returns a new instance of CommandLog.
281 282 283 284 285 |
# File 'lib/madeleine.rb', line 281 def initialize(path, file_service) id = self.class.highest_log(path, file_service) + 1 numbered_file = NumberedFile.new(path, "command_log", id) @file = file_service.open(numbered_file.name, 'wb') end |
Class Method Details
.highest_log(directory_name, file_service) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/madeleine.rb', line 300 def self.highest_log(directory_name, file_service) highest = 0 log_file_names(directory_name, file_service).each do |file_name| match = /^(\d{#{FILE_COUNTER_SIZE}})/.match(file_name) n = match[1].to_i if n > highest highest = n end end highest end |
.log_file_names(directory_name, file_service) ⇒ Object
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/madeleine.rb', line 270 def self.log_file_names(directory_name, file_service) return [] unless file_service.exist?(directory_name) result = file_service.dir_entries(directory_name).select {|name| name =~ /^\d{#{FILE_COUNTER_SIZE}}\.command_log$/ } result.each do |name| name.untaint end result.sort end |
Instance Method Details
#close ⇒ Object
287 288 289 |
# File 'lib/madeleine.rb', line 287 def close @file.close end |
#store(command) ⇒ Object
291 292 293 294 295 296 297 298 |
# File 'lib/madeleine.rb', line 291 def store(command) # Dumping to intermediate String instead of to IO directly, to make sure # all of the marshalling worked before we write anything to the log. data = Marshal.dump(command) @file.write(data) @file.flush @file.fsync end |