class Librato::Rails::VersionSpecifier

Public Class Methods

new(env) click to toggle source
# File lib/librato/rails/version_specifier.rb, line 8
def initialize(env)
  @env = env
end
supported(opts={}, &block) click to toggle source
# File lib/librato/rails/version_specifier.rb, line 4
def self.supported(opts={}, &block)
  new(::Rails).supported(opts, &block)
end

Public Instance Methods

supported(opts={}) { || ... } click to toggle source
# File lib/librato/rails/version_specifier.rb, line 12
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 Instance Methods

is_supported?(opts={}) click to toggle source
# File lib/librato/rails/version_specifier.rb, line 30
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
version() click to toggle source
# File lib/librato/rails/version_specifier.rb, line 26
def version
  [@env::VERSION::MAJOR, @env::VERSION::MINOR].compact.join('.')
end