Sha256: 31eedcd5534da2f1fa319ae9fd5e4901d099545d30cbacc13e3ff7e2f72ae964

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

# Helpers to detect Ruby versions

unless defined? Gem
  require 'rubygems'
end

# Compare the Ruby version with a version string
def ruby_version?(cmp, v)  
  rv =  Gem::Version.create(RUBY_VERSION.dup)
  v = Gem::Version.create(v)
  if cmp.to_sym==:'~>'
    rv = rv.release
    rv >= v && rv < v.bump
  else
    rv.send(cmp,v)
  end
end

# ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<=,v2)
def ruby_version_between?(v1, v2)  
  (Gem::Version.create(v1)..Gem::Version.create(v2)).include?(Gem::Version.create(RUBY_VERSION))
end

# ruby_version_between?(v1,v2) == ruby_version?(:>=,v1) && ruby_version?(:<,v2)
def ruby_version_between_ex?(v1, v2)  
  (Gem::Version.create(v1).-.Gem::Version.create(v2)).include?(Gem::Version.create(RUBY_VERSION))
end

# Execute code conditinally on Ruby version:
#    if_ruby_version :>=, '1.9.2' do
#      ...
#    end
def if_ruby_version(cmp, v)
  yield if ruby_version?(cmp, v)
end

def if_ruby_version_between(v1, v2)  
  yield if ruby_version_between?(v1, v2)
end

def if_ruby_version_between_ex(v1, v2)  
  yield if ruby_version_between_ex?(v1, v2)
end

def ruby_19(&blk)
  if_ruby_version :'~>', '1.9.0', &blk
end

def ruby_18(&blk)
  if_ruby_version :'~>', '1.8.0', &blk
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
modalsupport-0.9.2 lib/modalsupport/ruby_version.rb
modalsupport-0.9.1 lib/modalsupport/ruby_version.rb
modalsupport-0.9.0 lib/modalsupport/ruby_version.rb
modalsupport-0.8.3 lib/modalsupport/ruby_version.rb
modalsupport-0.8.2 lib/modalsupport/ruby_version.rb