class AbcSize::RubyVersion::Detector
Ruby version detector
Constants
- RUBY_VERSION_FILENAME
Public Instance Methods
call()
click to toggle source
# File lib/abc_size/ruby_version/detector.rb, line 11 def call file_version = return_file_version return_supported_version_if_version_supported(file_version) rescue Errno::ENOENT, EmptyFileError, UnknownFormatError => e rescue_detection_error(e) end
Private Instance Methods
rescue_detection_error(error)
click to toggle source
# File lib/abc_size/ruby_version/detector.rb, line 45 def rescue_detection_error(error) case error when Errno::ENOENT puts 'Not detected `.ruby-version` file!' when EmptyFileError puts 'Detected `.ruby-version` file, but file is empty!' when UnknownFormatError puts 'Detected `.ruby-version` file, but file contain unknown format!' end exit end
return_data()
click to toggle source
# File lib/abc_size/ruby_version/detector.rb, line 29 def return_data path = "#{Dir.pwd}/#{RUBY_VERSION_FILENAME}" data = File.read(path) raise EmptyFileError if data.empty? data end
return_file_version()
click to toggle source
# File lib/abc_size/ruby_version/detector.rb, line 21 def return_file_version data = return_data match_data = return_match_data(data) match_data[0].to_f end
return_match_data(data)
click to toggle source
# File lib/abc_size/ruby_version/detector.rb, line 38 def return_match_data(data) match_data = data.match(/\A\d+\.\d+/) raise UnknownFormatError if match_data.nil? match_data end