Class: Cliver::Dependency
- Inherits:
-
Object
- Object
- Cliver::Dependency
- Defined in:
- lib/cliver/dependency.rb
Overview
This is how a dependency is specified.
Constant Summary
- NotMet =
An exception class raised when assertion is not met
Class.new(ArgumentError)
- VersionMismatch =
An exception that is raised when executable present, but no version that matches the requirements is present.
Class.new(Dependency::NotMet)
- NotFound =
An exception that is raised when executable is not present at all.
Class.new(Dependency::NotMet)
- PARSABLE_GEM_VERSION =
A pattern for extracting a Gem::Version-parsable version
/[0-9]+(.[0-9]+){0,4}(.[a-zA-Z0-9]+)?/.freeze
Instance Method Summary (collapse)
-
- (void) check_compatibility!
One of these things is not like the other ones...
-
- (see #detect!) detect
The non-raise variant of #detect!.
-
- (String) detect!
Detects an installed version of the executable that matches the requirements.
-
- (Dependency) initialize(executables, *requirements, options = {}) {|executable_path| ... }
constructor
A new instance of Dependency.
-
- (Hash<String,String>) installed_versions {|executable_path, version| ... }
Get all the installed versions of the api-compatible executables.
Constructor Details
- (Dependency) initialize(executables, *requirements, options = {}) {|executable_path| ... }
A new instance of Dependency
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cliver/dependency.rb', line 50 def initialize(executables, *args, &detector) = args.last.kind_of?(Hash) ? args.pop : {} @detector = Detector::generate(detector || [:detector]) @filter = .fetch(:filter, Filter::IDENTITY).extend(Filter) @path = .fetch(:path, '*') @strict = .fetch(:strict, false) @executables = Array(executables).dup.freeze @requirement = args unless args.empty? check_compatibility! end |
Instance Method Details
- (void) check_compatibility!
This method returns an undefined value.
One of these things is not like the other ones... Some feature combinations just aren't compatible. This method ensures the the features selected for this object are compatible with each-other.
68 69 70 71 72 73 74 |
# File 'lib/cliver/dependency.rb', line 68 def check_compatibility! case when @executables.any? {|exe| exe[File::SEPARATOR] && !File.absolute_path?(exe) } # if the executable contains a path component, it *must* be absolute. raise ArgumentError, "Relative-path executable requirements are not supported." end end |
- (see #detect!) detect
The non-raise variant of #detect!
95 96 97 98 99 |
# File 'lib/cliver/dependency.rb', line 95 def detect detect! rescue Dependency::NotMet nil end |
- (String) detect!
Detects an installed version of the executable that matches the requirements.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cliver/dependency.rb', line 105 def detect! installed = {} installed_versions.each do |path, version| installed[path] = version return path if requirement_satisfied_by?(version) strict? end # dependency not met. raise the appropriate error. raise_not_found! if installed.empty? raise_version_mismatch!(installed) end |
- (Hash<String,String>) installed_versions {|executable_path, version| ... }
Get all the installed versions of the api-compatible executables. If a block is given, it yields once per found executable, lazily.
82 83 84 85 86 87 88 89 90 |
# File 'lib/cliver/dependency.rb', line 82 def installed_versions return enum_for(:installed_versions) unless block_given? find_executables.each do |executable_path| version = detect_version(executable_path) break(2) if yield(executable_path, version) end end |