Class: Gel::StubSet
- Inherits:
-
Object
- Object
- Gel::StubSet
- Defined in:
- lib/gel/stub_set.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #add(store, executables) ⇒ Object
- #bin(exe) ⇒ Object
- #create_stub(exe) ⇒ Object
-
#initialize(root) ⇒ StubSet
constructor
A new instance of StubSet.
- #remove(store, executables) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
6 7 8 |
# File 'lib/gel/stub_set.rb', line 6 def root @root end |
Instance Method Details
#add(store, executables) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/gel/stub_set.rb', line 14 def add(store, executables) @db.writing do executables.each do |exe| create_stub(exe) unless File.exist?(bin(exe)) @db[exe] = (@db[exe] || []) + [store] end end end |
#bin(exe) ⇒ Object
48 49 50 |
# File 'lib/gel/stub_set.rb', line 48 def bin(exe) File.join(@dir, exe) end |
#create_stub(exe) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gel/stub_set.rb', line 37 def create_stub(exe) Dir.mkdir(@dir) unless Dir.exist?(@dir) File.open(bin(exe), "w", 0755) do |f| f.write(<<STUB) #!/usr/bin/env gel stub #{exe} # This file is generated and managed by Gel. STUB end end |
#remove(store, executables) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gel/stub_set.rb', line 23 def remove(store, executables) @db.writing do executables.each do |exe| remaining_stores = (@db[exe] || []) - [store] if remaining_stores.empty? File.unlink(bin(exe)) @db.delete(exe) else @db[exe] = remaining_stores end end end end |