Class: EacRubyUtils::GemsRegistry::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/gems_registry/gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, gemspec) ⇒ Gem

Returns a new instance of Gem.



10
11
12
13
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 10

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

Instance Attribute Details

#gemspecObject (readonly)

Returns the value of attribute gemspec.



8
9
10
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 8

def gemspec
  @gemspec
end

#registryObject (readonly)

Returns the value of attribute registry.



8
9
10
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 8

def registry
  @registry
end

Instance Method Details

#found?Boolean

Returns:



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

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

#lib_file_found?Boolean

Returns:



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

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:



34
35
36
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 34

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

#registered_moduleObject



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

def registered_module
  return nil unless lib_file_found?

  require path_to_require
  path_to_require.classify.constantize
end