Class: JustOneLock::World
- Inherits:
-
Object
- Object
- JustOneLock::World
- Defined in:
- lib/just_one_lock/world.rb
Instance Attribute Summary collapse
-
#delete_files ⇒ Object
Returns the value of attribute delete_files.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #after_lock(name, file) ⇒ Object
- #before_lock(name, file) ⇒ Object
- #delete_unlocked_files ⇒ Object
-
#initialize ⇒ World
constructor
A new instance of World.
- #lock_paths ⇒ Object
- #puts(*args) ⇒ Object
Constructor Details
#initialize ⇒ World
Returns a new instance of World.
4 5 6 7 8 9 |
# File 'lib/just_one_lock/world.rb', line 4 def initialize @files = {} @output = $stdout @directory = '/tmp' @delete_files = true end |
Instance Attribute Details
#delete_files ⇒ Object
Returns the value of attribute delete_files.
2 3 4 |
# File 'lib/just_one_lock/world.rb', line 2 def delete_files @delete_files end |
#directory ⇒ Object
Returns the value of attribute directory.
2 3 4 |
# File 'lib/just_one_lock/world.rb', line 2 def directory @directory end |
#output ⇒ Object
Returns the value of attribute output.
2 3 4 |
# File 'lib/just_one_lock/world.rb', line 2 def output @output end |
Instance Method Details
#after_lock(name, file) ⇒ Object
30 31 32 |
# File 'lib/just_one_lock/world.rb', line 30 def after_lock(name, file) delete_unlocked_files if delete_files end |
#before_lock(name, file) ⇒ Object
26 27 28 |
# File 'lib/just_one_lock/world.rb', line 26 def before_lock(name, file) @files[name] = file end |
#delete_unlocked_files ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/just_one_lock/world.rb', line 11 def delete_unlocked_files paths_to_delete = [] @files.each do |path, f| if File.exists?(path) && f.closed? paths_to_delete << path end end paths_to_delete.each do |path| File.delete(path) @files.delete(path) end end |
#lock_paths ⇒ Object
34 35 36 |
# File 'lib/just_one_lock/world.rb', line 34 def lock_paths @files.keys end |
#puts(*args) ⇒ Object
38 39 40 |
# File 'lib/just_one_lock/world.rb', line 38 def puts(*args) output.puts(*args) end |