Sha256: 467010f8a9fa6fb5ea357566c2d1e391b5a784d75c1c71bc1ec8c232547b7d60
Contents?: true
Size: 1.05 KB
Versions: 10
Compression:
Stored size: 1.05 KB
Contents
module Librato module Rails class VersionSpecifier def self.supported(opts={}, &block) new(::Rails).supported(opts, &block) end def initialize(env) @env = env end def supported(opts={}, &block) unless block_given? raise VersionSpecifierError, 'version specific block required' end if !opts.key?(:min) && !opts.key?(:max) raise VersionSpecifierError, ':min and/or :max arguments required' end yield if is_supported?(opts) end private def version [@env::VERSION::MAJOR, @env::VERSION::MINOR].compact.join('.') end def is_supported?(opts={}) if version >= opts[:min].to_s && !opts.key?(:max) return true elsif version <= opts[:max].to_s && !opts.key?(:min) return true elsif version.between?(opts[:min].to_s, opts[:max].to_s) return true else return false end end end class VersionSpecifierError < StandardError; end end end
Version data entries
10 entries across 10 versions & 1 rubygems