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.


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

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

Instance Attribute Details

#loaded_gemsObject

Returns the value of attribute loaded_gems


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

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


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

def loaded_lockfiles
  @loaded_lockfiles
end

Instance Method Details

#gem_registered?(spec) ⇒ Boolean

Returns:

  • (Boolean)

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

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

#load_gem(spec) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/lock_jar/registry.rb', line 63

def load_gem(spec)
  return if gem_registered?(spec)

  register_gem(spec)
  gem_dir = spec.gem_dir

  lockfile = File.join(gem_dir, 'Jarfile.lock')

  return unless File.exist?(lockfile)

  puts "#{spec.name} has Jarfile.lock, loading jars"
  LockJar.load(lockfile)
end

#load_jars_for_gemsObject


77
78
79
80
81
82
83
# File 'lib/lock_jar/registry.rb', line 77

def load_jars_for_gems
  specs = Gem.loaded_specs
  return if specs.nil?

  gems = specs.keys - @loaded_gems.keys
  gems.each { |key| load_gem(specs[key]) }
end

#lockfile_registered?(lockfile) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/lock_jar/registry.rb', line 35

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

#register_gem(spec) ⇒ Object


55
56
57
# File 'lib/lock_jar/registry.rb', line 55

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

#register_jars(jars) ⇒ Object


45
46
47
48
49
50
51
52
53
# File 'lib/lock_jar/registry.rb', line 45

def register_jars(jars)
  return if jars.nil?

  jars_to_load = jars - @loaded_jars

  @loaded_jars += jars_to_load

  jars_to_load
end

#register_lockfile(lockfile) ⇒ Object


39
40
41
42
43
# File 'lib/lock_jar/registry.rb', line 39

def register_lockfile(lockfile)
  return if lockfile.nil? || lockfile_registered?(lockfile)

  @loaded_lockfiles << File.expand_path(lockfile)
end