Class: Jewel::Gem::Metadata
- Inherits:
-
Object
- Object
- Jewel::Gem::Metadata
- Defined in:
- lib/jewel/gem/metadata.rb
Overview
Stores Ruby gem metadata.
Instance Method Summary collapse
-
#all_dependencies ⇒ Hash<String, Array<String>>
Runtime and development dependencies.
-
#dependencies ⇒ Hash<String, Array<String>>
(also: #runtime_dependencies)
This gem’s runtime dependencies.
-
#development_dependencies ⇒ Hash<String, Array<String>>
This gem’s development dependencies.
-
#each_dependency(options = {}) {|gem_name, *requirements| ... } ⇒ Object
Yields dependencies to the given block, or returns an enumerator.
-
#gem_specification(existing_specification = nil) ⇒ ::Gem::Specification
(also: #spec, #gemspec, #to_spec, #specification)
The Gem::Specification.
-
#initialize(&block) ⇒ Metadata
constructor
Creates a new, empty set of gem metadata.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
Assigns or returns attributes from the associated gem specification.
Constructor Details
#initialize(&block) ⇒ Metadata
Creates a new, empty set of gem metadata.
If given a block, it will be evaluated in the context of the new instance.
16 17 18 |
# File 'lib/jewel/gem/metadata.rb', line 16 def initialize(&block) instance_eval &block unless block.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
Assigns or returns attributes from the associated gem specification. If it doesn’t respond to it, the attribute will be stored in this object.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jewel/gem/metadata.rb', line 23 def method_missing(method_name, *arguments, &block) method = method_name.to_s.gsub(/[=?!]+\z/ix, '').strip.intern count = arguments.count if count.zero? if spec.respond_to? method spec.send method else stored_attributes[method] end else writer_method = '='.prepend(method.to_s).intern if spec.respond_to? writer_method spec.send writer_method, *arguments else value = count == 1 ? arguments.first : arguments stored_attributes[method] = value end end end |
Instance Method Details
#all_dependencies ⇒ Hash<String, Array<String>>
Runtime and development dependencies. The former takes precedence in case of conflict.
67 68 69 |
# File 'lib/jewel/gem/metadata.rb', line 67 def all_dependencies development_dependencies.merge dependencies end |
#dependencies ⇒ Hash<String, Array<String>> Also known as: runtime_dependencies
This gem’s runtime dependencies.
47 48 49 |
# File 'lib/jewel/gem/metadata.rb', line 47 def dependencies convert_to_hash specification.runtime_dependencies end |
#development_dependencies ⇒ Hash<String, Array<String>>
This gem’s development dependencies.
57 58 59 |
# File 'lib/jewel/gem/metadata.rb', line 57 def development_dependencies convert_to_hash specification.development_dependencies end |
#each_dependency(options = {}) {|gem_name, *requirements| ... } ⇒ Object
Yields dependencies to the given block, or returns an enumerator.
79 80 81 82 83 84 85 86 87 |
# File 'lib/jewel/gem/metadata.rb', line 79 def each_dependency( = {}, &block) return enum_for :each_dependency, unless block_given? development = .fetch :development, false case development when :only then development_dependencies when true then all_dependencies else dependencies end.each &block end |
#gem_specification(existing_specification = nil) ⇒ ::Gem::Specification Also known as: spec, gemspec, to_spec, specification
The Gem::Specification. If passed an existing instance, it will be used instead.
96 97 98 99 100 101 |
# File 'lib/jewel/gem/metadata.rb', line 96 def gem_specification(existing_specification = nil) unless existing_specification.nil? @gem_specification = existing_specification end @gem_specification ||= ::Gem::Specification.new end |