Class: Cany::Dependency
- Inherits:
-
Object
- Object
- Cany::Dependency
- 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
-
#situations ⇒ Object
Returns the value of attribute situations.
Instance Method Summary collapse
- #build? ⇒ Boolean
-
#define_default(name, version = nil) ⇒ Object
Define the default package name and an optional version constraint for all.
-
#define_on_distro(distro, name, version = nil) ⇒ Object
Define the default package name and an optional version constraint for a distribution.
-
#define_on_distro_release(distro, release, name, version = nil) ⇒ Object
Define the package name and an optional version constraint for a distribution release.
-
#determine(distro, release) ⇒ Array<String, String>
Evaluation which packages (with version constraint) are needed for the given distrobution release.
-
#initialize(opts = {}) ⇒ Dependency
constructor
A new instance of Dependency.
- #runtime? ⇒ Boolean
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
#situations ⇒ Object
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
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
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
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
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.
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
28 |
# File 'lib/cany/dependency.rb', line 28 def runtime?; @situations.include? :runtime; end |