Class: Envandle::GemspecCache
- Inherits:
-
Object
- Object
- Envandle::GemspecCache
- Defined in:
- lib/envandle/gemspec_cache.rb
Defined Under Namespace
Classes: Reserved
Constant Summary collapse
- @@mutex =
Mutex.new
Instance Method Summary collapse
- #append(url, dir) ⇒ Object
- #find(url) ⇒ Object
-
#initialize(path) ⇒ GemspecCache
constructor
A new instance of GemspecCache.
- #load ⇒ Object
- #reserve ⇒ Object
- #with_file ⇒ Object
Constructor Details
#initialize(path) ⇒ GemspecCache
5 6 7 8 |
# File 'lib/envandle/gemspec_cache.rb', line 5 def initialize(path) @path = path FileUtils.mkdir_p @path end |
Instance Method Details
#append(url, dir) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/envandle/gemspec_cache.rb', line 20 def append(url, dir) with_file do |f| data = YAML.load(f.read) || {} data[url] = dir f.rewind f.write data.to_yaml f.flush f.truncate f.pos end end |
#find(url) ⇒ Object
37 38 39 40 41 |
# File 'lib/envandle/gemspec_cache.rb', line 37 def find(url) if dir = load[url] File.join(@path, dir) end end |
#load ⇒ Object
31 32 33 34 35 |
# File 'lib/envandle/gemspec_cache.rb', line 31 def load with_file do |f| YAML.load(f.read) || {} end end |
#reserve ⇒ Object
43 44 45 |
# File 'lib/envandle/gemspec_cache.rb', line 43 def reserve Reserved.new(@path) end |
#with_file ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/envandle/gemspec_cache.rb', line 10 def with_file path = File.join(@path, "list") @@mutex.synchronize do File.open(path, File::RDWR | File::CREAT) do |f| f.flock File::LOCK_EX yield f end end end |