Class: InstanceAccountant::Filer
- Inherits:
-
Object
- Object
- InstanceAccountant::Filer
- Defined in:
- lib/instance_accountant/filer.rb
Instance Method Summary collapse
-
#initialize(options = { }) ⇒ Filer
constructor
A new instance of Filer.
- #read ⇒ Object
- #write(hour) ⇒ Object
Constructor Details
#initialize(options = { }) ⇒ Filer
Returns a new instance of Filer.
5 6 7 8 9 10 |
# File 'lib/instance_accountant/filer.rb', line 5 def initialize = { } @file_klass = [:file_klass] || File @time_klass = [:time_klass] || Time @filepath = @file_klass. [:filepath] end |
Instance Method Details
#read ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/instance_accountant/filer.rb', line 12 def read @time_klass.parse @file_klass.open( @filepath, File::RDWR | File::CREAT, 0644 ) do |file| file.flock File::LOCK_EX file.read end rescue nil end |
#write(hour) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/instance_accountant/filer.rb', line 23 def write hour hour_string = hour.to_s @file_klass.open( @filepath, File::RDWR | File::CREAT, 0644 ) do |file| file.flock File::LOCK_EX file.rewind file.write hour_string end hour_string end |