Class: Cliver::Dependency
- Inherits:
-
Object
- Object
- Cliver::Dependency
- Defined in:
- lib/cliver/dependency.rb
Overview
This is how a dependency is specified.
Constant Summary collapse
- 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
-
#check_compatibility! ⇒ void
One of these things is not like the other ones…
-
#detect ⇒ see #detect!
The non-raise variant of #detect!.
-
#detect! ⇒ String
Detects an installed version of the executable that matches the requirements.
-
#initialize(executables, *requirements, options = {}) {|executable_path| ... } ⇒ Dependency
constructor
A new instance of Dependency.
-
#installed_versions {|executable_path, version| ... } ⇒ Hash<String,String>
Get all the installed versions of the api-compatible executables.
Constructor Details
#initialize(executables, *requirements, options = {}) {|executable_path| ... } ⇒ Dependency
Returns a new instance of Dependency.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cliver/dependency.rb', line 51 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
#check_compatibility! ⇒ void
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.
69 70 71 72 73 74 75 |
# File 'lib/cliver/dependency.rb', line 69 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 |
#detect ⇒ see #detect!
The non-raise variant of #detect!
96 97 98 99 100 |
# File 'lib/cliver/dependency.rb', line 96 def detect detect! rescue Dependency::NotMet nil end |
#detect! ⇒ String
Detects an installed version of the executable that matches the requirements.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cliver/dependency.rb', line 106 def detect! installed = {} installed_versions.each do |path, version| installed[path] = version return path if ENV['CLIVER_NO_VERIFY'] 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 |
#installed_versions {|executable_path, version| ... } ⇒ Hash<String,String>
Get all the installed versions of the api-compatible executables. If a block is given, it yields once per found executable, lazily.
83 84 85 86 87 88 89 90 91 |
# File 'lib/cliver/dependency.rb', line 83 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 |