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 Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
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
Returns a new instance of GemspecCache.
5 6 7 8 |
# File 'lib/envandle/gemspec_cache.rb', line 5 def initialize(path) @path = path FileUtils.mkdir_p @path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/envandle/gemspec_cache.rb', line 10 def path @path end |
Instance Method Details
#append(url, dir) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/envandle/gemspec_cache.rb', line 22 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
39 40 41 42 43 |
# File 'lib/envandle/gemspec_cache.rb', line 39 def find(url) if dir = load[url] File.join(@path, dir) end end |
#load ⇒ Object
33 34 35 36 37 |
# File 'lib/envandle/gemspec_cache.rb', line 33 def load with_file do |f| YAML.load(f.read) || {} end end |
#reserve ⇒ Object
45 46 47 |
# File 'lib/envandle/gemspec_cache.rb', line 45 def reserve Reserved.new(@path) end |
#with_file ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/envandle/gemspec_cache.rb', line 12 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 |