Class: TestLab::Labfile
- Inherits:
-
ZTK::DSL::Base
- Object
- ZTK::DSL::Base
- TestLab::Labfile
- Defined in:
- lib/testlab/labfile.rb
Overview
Labfile Class
Instance Method Summary collapse
- #compare_versions(version_one, version_two, comparison_operator = nil) ⇒ Object
- #config_dir ⇒ Object
-
#initialize(*args) ⇒ Labfile
constructor
A new instance of Labfile.
- #invalid_version ⇒ Object
- #repo_dir ⇒ Object
Constructor Details
#initialize(*args) ⇒ Labfile
Returns a new instance of Labfile.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/testlab/labfile.rb', line 18 def initialize(*args) @ui = TestLab.ui @ui.logger.debug { "Loading Labfile" } super(*args) @ui.logger.debug { "Labfile '#{self.id}' Loaded" } if version.nil? raise LabfileError, 'You must version the Labfile!' else @ui.logger.debug { "Labfile Version: #{version}" } version_arguments = version.split @ui.logger.debug { "version_arguments=#{version_arguments.inspect}" } if version_arguments.count == 1 compare_versions(TestLab::VERSION, version_arguments.first) elsif version_arguments.count == 2 compare_versions(TestLab::VERSION, version_arguments.last, version_arguments.first) else raise LabfileError, 'Invalid Labfile version attribute!' end end end |
Instance Method Details
#compare_versions(version_one, version_two, comparison_operator = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/testlab/labfile.rb', line 42 def compare_versions(version_one, version_two, comparison_operator=nil) v1_splat = version_one.split('.') v2_splat = version_two.split('.') max_length = [v1_splat.map(&:length).max, v2_splat.map(&:length).max].max v1 = v1_splat.collect{ |element| "%0#{max_length}d" % element.to_i }.join('.') v2 = v2_splat.collect{ |element| "%0#{max_length}d" % element.to_i }.join('.') @ui.logger.debug { "v1=#{v1.inspect}" } @ui.logger.debug { "v2=#{v2.inspect}" } @ui.logger.debug { "max_length=#{max_length.inspect}" } if comparison_operator.nil? invalid_version if v1 != v2 else invalid_version if !v1.send(comparison_operator.to_sym, v2) end end |
#config_dir ⇒ Object
66 67 68 |
# File 'lib/testlab/labfile.rb', line 66 def config_dir self.testlab.config_dir end |
#invalid_version ⇒ Object
62 63 64 |
# File 'lib/testlab/labfile.rb', line 62 def invalid_version raise LabfileError, "This Labfile is not compatible with this version of TestLab! (#{self.version})" end |
#repo_dir ⇒ Object
70 71 72 |
# File 'lib/testlab/labfile.rb', line 70 def repo_dir self.testlab.repo_dir end |