Class: Saxon::FeatureFlags::Version Private
- Inherits:
-
Object
- Object
- Saxon::FeatureFlags::Version
- Defined in:
- lib/saxon/feature_flags/version.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Restrict a specific method to only work with the specified Saxon version
Instance Attribute Summary collapse
-
#comparison_operator ⇒ Symbol
readonly
private
The extracted comparison operator.
-
#constraint_string ⇒ String
readonly
private
The complete constraint string.
-
#version_string ⇒ String
readonly
private
The extracted version string.
Class Method Summary collapse
-
.create(klass, method_name, version_constraint) ⇒ Object
private
Modify the method so that it will only run if the version constraint is satisfied.
Instance Method Summary collapse
-
#constraint_version ⇒ Saxon::Version::Library
private
Generates a Version::Library representing the version specified in the constraint that can be compared with the loaded Saxon version.
-
#initialize(constraint_string) ⇒ Version
constructor
private
Create a version constraint check from the supplied constraint string.
-
#ok? ⇒ Boolean
private
Reports if the version constraint is satisfied or not.
Constructor Details
#initialize(constraint_string) ⇒ Version
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a version constraint check from the supplied constraint string
58 59 60 61 |
# File 'lib/saxon/feature_flags/version.rb', line 58 def initialize(constraint_string) @constraint_string = constraint_string @comparison_operator, @version_string = parse_version_constraint(constraint_string) end |
Instance Attribute Details
#comparison_operator ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the extracted comparison operator.
51 52 53 |
# File 'lib/saxon/feature_flags/version.rb', line 51 def comparison_operator @comparison_operator end |
#constraint_string ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the complete constraint string.
49 50 51 |
# File 'lib/saxon/feature_flags/version.rb', line 49 def constraint_string @constraint_string end |
#version_string ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the extracted version string.
53 54 55 |
# File 'lib/saxon/feature_flags/version.rb', line 53 def version_string @version_string end |
Class Method Details
.create(klass, method_name, version_constraint) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Modify the method so that it will only run if the version constraint is satisfied.
We can’t know what version of Saxon is in use at code load time, only once Loader#load! has been called, either explicitly or by calling a method which requires a Saxon Java object. Therefore, we have to check this the first time someone calls the method.
Creating this check replaces the method on the target class with one that checks the version, and runs the original version if its constraint is satisfied.
To avoid performing the check every time the method is called, once we know whether or not the constraint is satisfied, we assume that the verion of Saxon cannot be unloaded and a new one loaded in its place and replace our version checking method with the original (if the constraint is passed), or with one that simply raises the constraint error.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/saxon/feature_flags/version.rb', line 30 def self.create(klass, method_name, version_constraint) method = klass.instance_method(method_name) version_check = new(version_constraint) klass.send(:define_method, method_name, ->(*args) { if version_check.ok? klass.send(:define_method, method_name, method) method.bind(self).call(*args) else klass.send(:define_method, method_name, ->(*args) { raise UnavailableInThisSaxonVersionError }) raise UnavailableInThisSaxonVersionError end }) end |
Instance Method Details
#constraint_version ⇒ Saxon::Version::Library
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a Version::Library representing the version specified in the constraint that can be compared with the loaded Saxon version
74 75 76 |
# File 'lib/saxon/feature_flags/version.rb', line 74 def constraint_version @constraint_version ||= Saxon::Version::Library.new(version_string, 'HE') end |
#ok? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reports if the version constraint is satisfied or not.
66 67 68 |
# File 'lib/saxon/feature_flags/version.rb', line 66 def ok? Saxon::Version::Library.loaded_version.send(comparison_operator, constraint_version) end |