Class: Cany::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/cany/dependency.rb

Overview

This class representing a dependency on an abstract object like a gem or a external software.

Depending on the platform different packages are needed to satisfy the dependency. This class stores which packages (and optional a version constraint) is needed for every platform, distribution or distribution release.

This class differs between two different situation where dependencies are needed: to build the package (:build) or to run/use the packages (:runtime).

A dependency has also a priority:

- :required: The dependency have to be fulfilled in every situation otherwise it is not
  possible to build or run the application.

Other priorities are planed but currently not implemented.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Dependency

Returns a new instance of Dependency.



16
17
18
19
20
21
22
# File 'lib/cany/dependency.rb', line 16

def initialize(opts={})
  opts = { situations: [:runtime] }.merge opts
  @default = []
  @distros = Cany.hash_with_array_as_default
  @distro_releases ||= Cany.hash_with_array_as_default
  self.situations = opts[:situations]
end

Instance Attribute Details

#situationsObject

Returns the value of attribute situations.



24
25
26
# File 'lib/cany/dependency.rb', line 24

def situations
  @situations
end

Instance Method Details

#build?Boolean

Returns:

  • (Boolean)


29
# File 'lib/cany/dependency.rb', line 29

def build?; @situations.include? :build; end

#define_default(name, version = nil) ⇒ Object

Define the default package name and an optional version constraint for all

Parameters:

  • name (String)

    A package name

  • version (String, nil) (defaults to: nil)

    A version constraint



34
35
36
# File 'lib/cany/dependency.rb', line 34

def define_default(name, version=nil)
  default << [name, version]
end

#define_on_distro(distro, name, version = nil) ⇒ Object

Define the default package name and an optional version constraint for a distribution

Parameters:

  • distro (Symbol)

    The distribution name like :ubuntu, :debian …

  • name (String)

    A package name

  • version (String, nil) (defaults to: nil)

    A version constraint



42
43
44
# File 'lib/cany/dependency.rb', line 42

def define_on_distro(distro, name, version=nil)
  distros[distro] << [name, version]
end

#define_on_distro_release(distro, release, name, version = nil) ⇒ Object

Define the package name and an optional version constraint for a distribution release

Parameters:

  • distro (Symbol)

    The distribution name like :ubuntu, :debian …

  • release (Symbol)

    The distribution release like :precise for ubuntu 12.04

  • name (String)

    A package name

  • version (String, nil) (defaults to: nil)

    A version constraint



51
52
53
# File 'lib/cany/dependency.rb', line 51

def define_on_distro_release(distro, release, name, version=nil)
  distro_releases[[distro, release]] << [name, version]
end

#determine(distro, release) ⇒ Array<String, String>

Evaluation which packages (with version constraint) are needed for the given distrobution release.

Parameters:

  • distro (Symbol)

    The distribution name like :ubuntu, :debian …

  • release (Symbol)

    The distribution release like :precise for ubuntu 12.04

Returns:

  • (Array<String, String>)


60
61
62
63
64
# File 'lib/cany/dependency.rb', line 60

def determine(distro, release)
  return distro_releases[[distro, release]] if distro_releases.has_key? [distro, release]
  return distros[distro] if distros.has_key? distro
  default
end

#runtime?Boolean

Returns:

  • (Boolean)


28
# File 'lib/cany/dependency.rb', line 28

def runtime?; @situations.include? :runtime; end