Class: Jewel::Gem

Inherits:
Object
  • Object
show all
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.

Author:

  • Matheus Afonso Martins Moreira

Since:

  • 0.0.1

Defined Under Namespace

Classes: Metadata, Root

Class Method Summary collapse

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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :development (true, false, :only) — default: false

    which set of dependencies should be activated

Since:

  • 0.0.2



85
86
87
88
89
# File 'lib/jewel/gem.rb', line 85

def activate_dependencies!(options = {})
  .each_dependency options 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.

Examples:

depend_on :jewel    # runtime dependency

development do
  depend_on :rspec  # development dependency
end

Parameters:

  • gem (String, Symbol, #to_s)

    the name of the gem

  • requirements (Array<String>)

    the version requirements

See Also:

Since:

  • 0.0.1



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.

Examples:

development do
  depend_on :rspec
end

Parameters:

  • block (Proc)

    the block to evaluate

See Also:

Since:

  • 0.0.1



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

.metadataJewel::Gem::Metadata

The gem metadata.

Returns:

Since:

  • 0.0.1



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.

Since:

  • 0.0.1



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.

Parameters:

  • name (String, Symbol, #to_s) (defaults to: nil)

    the name of the gem

Returns:

  • (String)

    the name of the gem

Since:

  • 0.0.1



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.

Parameters:

  • relative_to (String, #to_s) (defaults to: nil)

    the gem root relative to the current directory

Returns:

  • (String)

    the gem root as an absolute path

Since:

  • 0.0.2



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.expand_path(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.

Parameters:

  • existing_specification (::Gem::Specification) (defaults to: nil)

    the existing instance

Returns:

  • (::Gem::Specification)

    the gem specification

See Also:

Since:

  • 0.0.1



113
114
115
# File 'lib/jewel/gem.rb', line 113

def specification(existing_specification = nil)
  .gem_specification existing_specification
end