Class: LockJar::Registry
- Inherits:
-
Object
- Object
- LockJar::Registry
- Includes:
- Singleton
- Defined in:
- lib/lock_jar/registry.rb
Overview
Registry of resources loaded by LockJar
Instance Attribute Summary collapse
-
#loaded_gems ⇒ Object
Returns the value of attribute loaded_gems.
-
#loaded_jars ⇒ Object
Returns the value of attribute loaded_jars.
-
#loaded_lockfiles ⇒ Object
Returns the value of attribute loaded_lockfiles.
Instance Method Summary collapse
- #gem_registered?(spec) ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #load_gem(spec) ⇒ Object
- #load_jars_for_gems ⇒ Object
- #lockfile_registered?(lockfile) ⇒ Boolean
- #register_gem(spec) ⇒ Object
- #register_jars(jars) ⇒ Object
- #register_lockfile(lockfile) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
28 29 30 31 32 |
# File 'lib/lock_jar/registry.rb', line 28 def initialize @loaded_gems = {} @loaded_jars = [] @loaded_lockfiles = [] end |
Instance Attribute Details
#loaded_gems ⇒ Object
Returns the value of attribute loaded_gems.
24 25 26 |
# File 'lib/lock_jar/registry.rb', line 24 def loaded_gems @loaded_gems end |
#loaded_jars ⇒ Object
Returns the value of attribute loaded_jars.
25 26 27 |
# File 'lib/lock_jar/registry.rb', line 25 def loaded_jars @loaded_jars end |
#loaded_lockfiles ⇒ Object
Returns the value of attribute loaded_lockfiles.
26 27 28 |
# File 'lib/lock_jar/registry.rb', line 26 def loaded_lockfiles @loaded_lockfiles end |
Instance Method Details
#gem_registered?(spec) ⇒ Boolean
60 61 62 |
# File 'lib/lock_jar/registry.rb', line 60 def gem_registered?( spec ) !@loaded_gems[spec.name].nil? end |
#load_gem(spec) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/lock_jar/registry.rb', line 64 def load_gem( spec ) unless gem_registered?( spec ) register_gem(spec) gem_dir = spec.gem_dir lockfile = File.join( gem_dir, "Jarfile.lock" ) if File.exists?( lockfile ) puts "#{spec.name} has Jarfile.lock, loading jars" LockJar.load( lockfile ) end end end |
#load_jars_for_gems ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lock_jar/registry.rb', line 78 def load_jars_for_gems specs = Gem.loaded_specs if specs gems = specs.keys - @loaded_gems.keys if gems.size > 0 gems.each do |key| spec = specs[key] load_gem( spec ) end end end end |
#lockfile_registered?(lockfile) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/lock_jar/registry.rb', line 34 def lockfile_registered?( lockfile ) if lockfile @loaded_lockfiles.include? File.( lockfile ) end end |
#register_gem(spec) ⇒ Object
56 57 58 |
# File 'lib/lock_jar/registry.rb', line 56 def register_gem( spec ) @loaded_gems[spec.name] = spec end |
#register_jars(jars) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/lock_jar/registry.rb', line 46 def register_jars( jars ) if jars jars_to_load = jars - @loaded_jars @loaded_jars += jars_to_load jars_to_load end end |
#register_lockfile(lockfile) ⇒ Object
40 41 42 43 44 |
# File 'lib/lock_jar/registry.rb', line 40 def register_lockfile( lockfile ) if lockfile && !lockfile_registered?( lockfile ) @loaded_lockfiles << File.( lockfile ) end end |