Module: Inventory::Dependency

Overview

Some form of dependency of this project. A dependency can be #required, added to a gem specification, and has various information associated with it: #name, #major, #minor, #patch, and #feature.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#featureString (readonly)

Returns The name of the feature to #require.

Returns:

  • (String)

    The name of the feature to #require



71
72
73
# File 'lib/inventory-1.0/dependency.rb', line 71

def feature
  @feature
end

#majorInteger (readonly)

Returns The major version atom of the dependency.

Returns:

  • (Integer)

    The major version atom of the dependency



62
63
64
# File 'lib/inventory-1.0/dependency.rb', line 62

def major
  @major
end

#minorInteger (readonly)

Returns The minor version atom of the dependency.

Returns:

  • (Integer)

    The minor version atom of the dependency



65
66
67
# File 'lib/inventory-1.0/dependency.rb', line 65

def minor
  @minor
end

#nameString (readonly)

Returns The name of the project that this dependency pertains to.

Returns:

  • (String)

    The name of the project that this dependency pertains to



59
60
61
# File 'lib/inventory-1.0/dependency.rb', line 59

def name
  @name
end

#patchInteger (readonly)

Returns The patch version atom of the dependency.

Returns:

  • (Integer)

    The patch version atom of the dependency



68
69
70
# File 'lib/inventory-1.0/dependency.rb', line 68

def patch
  @patch
end

Instance Method Details

#add_to_gem_specification(specification) ⇒ self

Add the receiver as a runtime dependency to SPECIFICATION.

Parameters:

  • specification (Gem::Specification)

Returns:

  • (self)


48
49
50
51
# File 'lib/inventory-1.0/dependency.rb', line 48

def add_to_gem_specification(specification)
  specification.add_runtime_dependency name, gem_requirement
  self
end

#initialize(name, major, minor, patch, options = {}) ⇒ Object

Sets up a dependency on project NAME, version MAJOR, MINOR, PATCH, along with any OPTIONS. Any methods may be overridden on the instance in the optionally #instance_exec’d block, if a dependency has any non-standard requirements.

Parameters:

  • name (String)
  • major (Integer)
  • minor (Integer)
  • patch (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :feature (String) — default: '%s-%s.0' % [name.gsub('-', '/'), major]

    The name of the feature to load



20
21
22
23
24
25
26
27
28
# File 'lib/inventory-1.0/dependency.rb', line 20

def initialize(name, major, minor, patch, options = {})
  @name, @major, @minor, @patch = name, major, minor, patch
  @altfeature = nil
  @feature = options.fetch(:feature){
    @altfeature = '%s-%d.0' % [name.gsub('-', '/'), major]
    '%s-%d.0' % [name, major]
  }
  instance_exec(&Proc.new) if block_given?
end

#requireBoolean

Returns The result of requiring #feature.

Returns:

  • (Boolean)

    The result of requiring #feature



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/inventory-1.0/dependency.rb', line 31

def require
  super feature
rescue LoadError => e
  if @altfeature and (not e.respond_to? :path or e.path.end_with? feature)
    begin
      super @altfeature
    rescue LoadError
      raise e
    end
  else
    raise e
  end
end

#to_sString

Returns The version atoms on the form #major.#minor.#patch.

Returns:



54
55
56
# File 'lib/inventory-1.0/dependency.rb', line 54

def to_s
  [major, minor, patch].join('.')
end