Class: EacRubyUtils::GemsRegistry::Gem
Constant Summary
Constants included
from SimpleCache
SimpleCache::UNCACHED_METHOD_NAME_SUFFIX, SimpleCache::UNCACHED_METHOD_PATTERN
Instance Attribute Summary collapse
Instance Method Summary
collapse
#method_missing, #reset_cache, #respond_to_missing?, #sanitize_cache_key, 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
Returns the value of attribute gemspec.
13
14
15
|
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 13
def gemspec
@gemspec
end
|
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
|
#dependencies ⇒ Object
24
25
26
|
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 24
def dependencies
@dependencies ||= dependencies_uncached end
|
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
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_require ⇒ String
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_module ⇒ Object
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.camelize.constantize
end
|
60
61
62
|
# File 'lib/eac_ruby_utils/gems_registry/gem.rb', line 60
def to_s
"#{self.class.name}[#{gemspec.name}]"
end
|