Class: EacRubyUtils::GemsRegistry::Gem

Inherits:
Object
  • Object
show all
Includes:
Comparable, SimpleCache
Defined in:
lib/eac_ruby_utils/gems_registry/gem.rb

Constant Summary

Constants included from SimpleCache

SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, SimpleCache::UNCACHED_METHOD_PATTERN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleCache

#method_missing, #reset_cache, #respond_to_missing?, uncached_method_name

Constructor Details

#initialize(registry, gemspec) ⇒ Gem

Returns a new instance of Gem.



15
16
17
18
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 15

def initialize(registry, gemspec)
  @registry = registry
  @gemspec = gemspec
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EacRubyUtils::SimpleCache

Instance Attribute Details

#gemspecObject (readonly)

Returns the value of attribute gemspec.



13
14
15
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 13

def gemspec
  @gemspec
end

#registryObject (readonly)

Returns the value of attribute registry.



13
14
15
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 13

def registry
  @registry
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 28

def <=>(other)
  sd = depend_on(other)
  od = other.depend_on(self)
  return 1 if sd && !od
  return -1 if od && !sd

  gemspec.name <=> other.gemspec.name
end

#depend_on(gem) ⇒ Object



20
21
22
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 20

def depend_on(gem)
  dependencies.lazy.map(&:name).include?(gem.gemspec.name)
end

#dependenciesObject



24
25
26
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 24

def dependencies
  @dependencies ||= dependencies_uncached # dependencies_uncached
end

#found?Boolean

Returns:



37
38
39
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 37

def found?
  lib_file_found? && registered_module.is_a?(::Module)
end

#lib_file_found?Boolean

Returns:



41
42
43
44
45
46
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 41

def lib_file_found?
  gemspec.require_paths.any? do |require_path|
    ::Pathname.new(require_path).expand_path(gemspec.gem_dir).join(path_to_require + '.rb')
              .file?
  end
end

#path_to_requireString

Returns:



56
57
58
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 56

def path_to_require
  gemspec.name.gsub('-', '/') + '/' + registry.module_suffix.underscore
end

#registered_moduleObject



48
49
50
51
52
53
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 48

def registered_module
  return nil unless lib_file_found?

  require path_to_require
  path_to_require.classify.constantize
end