Class: EacRubyUtils::GemsRegistry::Gem

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

Defined Under Namespace

Modules: Dependencies, PathsToRequire

Constant Summary

Constants included from SimpleCache

SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, SimpleCache::UNCACHED_METHOD_PATTERN

Constants included from PathsToRequire

PathsToRequire::ROOT_MODULE_REQUIRE_PATTERNS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SimpleCache

#method_missing, #reset_cache, #respond_to_missing?, #sanitize_cache_key, uncached_method_name

Methods included from PathsToRequire

#absolute_require_paths, #path_to_require, #to_s

Methods included from Dependencies

#depend_on, #dependencies

Constructor Details

#initialize(registry, gemspec) ⇒ Gem

Returns a new instance of Gem.



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

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.



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

def gemspec
  @gemspec
end

#registryObject (readonly)

Returns the value of attribute registry.



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

def registry
  @registry
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 23

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

#found?Boolean

Returns:



32
33
34
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 32

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

#lib_file_found?Boolean

Returns:



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

def lib_file_found?
  absolute_require_paths(direct_path_to_require).any?(&:file?)
end

#registered_moduleObject



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

def registered_module
  return nil unless lib_file_found?

  require path_to_require
  direct_path_to_require.camelize.constantize
end