Class: LockJar::Registry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/lock_jar/registry.rb

Overview

Registry of resources loaded by LockJar

Author:

  • Michael Guymon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



30
31
32
33
34
# File 'lib/lock_jar/registry.rb', line 30

def initialize
  @loaded_gems = {}
  @loaded_jars = []
  @loaded_lockfiles = []
end

Instance Attribute Details

#loaded_gemsObject

Returns the value of attribute loaded_gems.



26
27
28
# File 'lib/lock_jar/registry.rb', line 26

def loaded_gems
  @loaded_gems
end

#loaded_jarsObject

Returns the value of attribute loaded_jars.



27
28
29
# File 'lib/lock_jar/registry.rb', line 27

def loaded_jars
  @loaded_jars
end

#loaded_lockfilesObject

Returns the value of attribute loaded_lockfiles.



28
29
30
# File 'lib/lock_jar/registry.rb', line 28

def loaded_lockfiles
  @loaded_lockfiles
end

Instance Method Details

#gem_registered?(spec) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/lock_jar/registry.rb', line 62

def gem_registered?( spec )
  !@loaded_gems[spec.name].nil?
end

#load_gem(spec) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lock_jar/registry.rb', line 66

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_gemsObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/lock_jar/registry.rb', line 80

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

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/lock_jar/registry.rb', line 36

def lockfile_registered?( lockfile )
  if lockfile
    @loaded_lockfiles.include? File.expand_path( lockfile )
  end
end

#register_gem(spec) ⇒ Object



58
59
60
# File 'lib/lock_jar/registry.rb', line 58

def register_gem( spec )
  @loaded_gems[spec.name] = spec
end

#register_jars(jars) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/lock_jar/registry.rb', line 48

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



42
43
44
45
46
# File 'lib/lock_jar/registry.rb', line 42

def register_lockfile( lockfile )
  if lockfile && !lockfile_registered?( lockfile )
    @loaded_lockfiles << File.expand_path( lockfile )
  end
end