lib/testlab/labfile.rb in testlab-1.9.2 vs lib/testlab/labfile.rb in testlab-1.10.0
- old
+ new
@@ -25,23 +25,43 @@
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.inspect }
+ @ui.logger.debug { "version_arguments=#{version_arguments.inspect}" }
if version_arguments.count == 1
- if (TestLab::VERSION != version_arguments.first)
- raise LabfileError, "This Labfile is not compatible with this version of TestLab! (#{version})"
- end
+ compare_versions(TestLab::VERSION, version_arguments.first)
elsif version_arguments.count == 2
- if !TestLab::VERSION.send(version_arguments.first, version_arguments.last)
- raise LabfileError, "This Labfile is not compatible with this version of TestLab! (#{version})"
- end
+ compare_versions(TestLab::VERSION, version_arguments.last, version_arguments.first)
else
- raise LabfileError, 'Invalid version!'
+ raise LabfileError, 'Invalid Labfile version attribute!'
end
end
+ end
+
+ 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
+
+ def invalid_version
+ raise LabfileError, "This Labfile is not compatible with this version of TestLab! (#{self.version})"
end
def config_dir
self.testlab.config_dir
end