Class: Jewel::Gem
- Inherits:
-
Object
- Object
- Jewel::Gem
- Defined in:
- lib/jewel/gem.rb,
lib/jewel/gem.rb,
lib/jewel/gem/root.rb,
lib/jewel/gem/metadata.rb
Overview
Stores information about a gem.
Defined Under Namespace
Class Method Summary collapse
-
.activate_dependencies!(options = {}) ⇒ Object
Makes sure the correct versions of this gem’s dependencies are loaded at runtime, no matter which versions are installed locally.
-
.depend_on(gem, *requirements) ⇒ Object
(also: depends_on)
Adds a runtime dependency.
-
.development(&block) ⇒ Object
Executes the given block within a development context, turning runtime dependencies into development dependencies.
-
.metadata ⇒ Jewel::Gem::Metadata
The gem metadata.
-
.method_missing(method_name, *arguments, &block) ⇒ Object
Forwards everything to this gem’s Gem.metadata.
-
.name!(name = nil) ⇒ String
Sets the name of the gem.
-
.root(relative_to = nil) ⇒ String
Sets the root of the gem, relative to the directory where the current file is located.
-
.specification(existing_specification = nil) ⇒ ::Gem::Specification
(also: spec, to_spec)
Returns this gem’s specification.
Class Method Details
.activate_dependencies!(options = {}) ⇒ Object
Makes sure the correct versions of this gem’s dependencies are loaded at runtime, no matter which versions are installed locally.
85 86 87 88 89 |
# File 'lib/jewel/gem.rb', line 85 def activate_dependencies!( = {}) .each_dependency do |name, *requirements| gem name, *requirements unless requirements.empty? end end |
.depend_on(gem, *requirements) ⇒ Object Also known as: depends_on
Adds a runtime dependency.
If called within a development context, a development dependency will be added instead.
72 73 74 75 |
# File 'lib/jewel/gem.rb', line 72 def depend_on(gem, *requirements) method = development? ? :add_development_dependency : :add_dependency specification.send method, gem.to_s, *requirements end |
.development(&block) ⇒ Object
Executes the given block within a development context, turning runtime dependencies into development dependencies.
100 101 102 103 104 105 |
# File 'lib/jewel/gem.rb', line 100 def development(&block) @development = true instance_eval &block ensure @development = false end |
.metadata ⇒ Jewel::Gem::Metadata
The gem metadata.
20 21 22 |
# File 'lib/jewel/gem.rb', line 20 def @metadata ||= Jewel::Gem::Metadata.new end |
.method_missing(method_name, *arguments, &block) ⇒ Object
Forwards everything to this gem’s metadata.
25 26 27 |
# File 'lib/jewel/gem.rb', line 25 def method_missing(method_name, *arguments, &block) .send method_name, *arguments, &block end |
.name!(name = nil) ⇒ String
Sets the name of the gem. Returns the name if not given an argument.
33 34 35 36 |
# File 'lib/jewel/gem.rb', line 33 def name!(name = nil) arguments = [ name ].compact.map &:to_s .send :name, *arguments end |
.root(relative_to = nil) ⇒ String
Sets the root of the gem, relative to the directory where the current file is located. Returns the gem root if not given an argument.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jewel/gem.rb', line 45 def root(relative_to = nil) arguments = [] unless relative_to.nil? relative_to = relative_to.to_s # caller returns an array of strings that are like “file:line” or “file:line: in `method’” file = caller.first.sub /:\d+(:in .*)?\z/, '' directory = File.dirname file path = File.(relative_to, directory) arguments.push Jewel::Gem::Root.new path end .send :root, *arguments end |
.specification(existing_specification = nil) ⇒ ::Gem::Specification Also known as: spec, to_spec
Returns this gem’s specification. If passed an existing instance, it will be stored as this gem’s specification.
113 114 115 |
# File 'lib/jewel/gem.rb', line 113 def specification(existing_specification = nil) .gem_specification existing_specification end |