Class: TimeBucketStream::Claim
- Inherits:
-
Object
- Object
- TimeBucketStream::Claim
- Defined in:
- lib/time_bucket_stream/claim.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(name:, path:, lock_file:) ⇒ Claim
constructor
A new instance of Claim.
- #quarantine(paths:, reason:, metadata: {}, clock: Time) ⇒ Object
- #read_lines ⇒ Object
- #release ⇒ Object
Constructor Details
#initialize(name:, path:, lock_file:) ⇒ Claim
Returns a new instance of Claim.
12 13 14 15 16 |
# File 'lib/time_bucket_stream/claim.rb', line 12 def initialize(name:, path:, lock_file:) @name = name @path = path @lock_file = lock_file end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/time_bucket_stream/claim.rb', line 10 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/time_bucket_stream/claim.rb', line 10 def path @path end |
Instance Method Details
#delete ⇒ Object
24 25 26 27 28 |
# File 'lib/time_bucket_stream/claim.rb', line 24 def delete FileUtils.rm_f(path) ensure release end |
#quarantine(paths:, reason:, metadata: {}, clock: Time) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/time_bucket_stream/claim.rb', line 30 def quarantine(paths:, reason:, metadata: {}, clock: Time) quarantine_name = quarantine_name_for(current_time(clock)) quarantine_path = paths.quarantine_log_for(quarantine_name) = paths.(quarantine_name) FileUtils.mkdir_p(paths.quarantine) File.rename(path, quarantine_path) (, ( quarantine_name: quarantine_name, quarantine_path: quarantine_path, reason: reason, metadata: , clock: clock )) quarantine_path ensure release end |
#read_lines ⇒ Object
18 19 20 21 22 |
# File 'lib/time_bucket_stream/claim.rb', line 18 def read_lines File.readlines(path, chomp: true) rescue SystemCallError, IOError [] end |
#release ⇒ Object
49 50 51 52 53 |
# File 'lib/time_bucket_stream/claim.rb', line 49 def release unlock_file(@lock_file) close_file(@lock_file) @lock_file = nil end |