module PatchLife

Public Class Methods

define_patch_life(options={}) { || ... } click to toggle source
# File lib/patch_life.rb, line 2
def define_patch_life(options={}, &blk)
  raise(ArgumentError, "define_patch requires a :version argument to be set") unless options[:version]
  raise(ArgumentError, "define_patch requires a :patch argument to be set") unless options[:patch]
  raise(ArgumentError, "define_patch requires either a :message argument, a block to yield, or both") unless options[:message] || block_given?

  past_due_version = Gem::Version.new(ruby_version) > Gem::Version.new(options[:version])
  equivalent_version = Gem::Version.new(ruby_version) == Gem::Version.new(options[:version])
  past_due_patch = ruby_patch_level >= options[:patch].to_i 
  past_due = past_due_version || (equivalent_version && past_due_patch)

  Kernel.warn(options[:message]) if past_due && options[:message]
  yield if !past_due && block_given?
  #Don't want to return anything at all...
  nil
end
ruby_patch_level() click to toggle source
# File lib/patch_life.rb, line 24
def ruby_patch_level
  RUBY_PATCHLEVEL
end
ruby_version() click to toggle source
# File lib/patch_life.rb, line 19
def ruby_version
  RUBY_VERSION.dup
end

Private Instance Methods

define_patch_life(options={}) { || ... } click to toggle source
# File lib/patch_life.rb, line 2
def define_patch_life(options={}, &blk)
  raise(ArgumentError, "define_patch requires a :version argument to be set") unless options[:version]
  raise(ArgumentError, "define_patch requires a :patch argument to be set") unless options[:patch]
  raise(ArgumentError, "define_patch requires either a :message argument, a block to yield, or both") unless options[:message] || block_given?

  past_due_version = Gem::Version.new(ruby_version) > Gem::Version.new(options[:version])
  equivalent_version = Gem::Version.new(ruby_version) == Gem::Version.new(options[:version])
  past_due_patch = ruby_patch_level >= options[:patch].to_i 
  past_due = past_due_version || (equivalent_version && past_due_patch)

  Kernel.warn(options[:message]) if past_due && options[:message]
  yield if !past_due && block_given?
  #Don't want to return anything at all...
  nil
end
ruby_patch_level() click to toggle source
# File lib/patch_life.rb, line 24
def ruby_patch_level
  RUBY_PATCHLEVEL
end
ruby_version() click to toggle source
# File lib/patch_life.rb, line 19
def ruby_version
  RUBY_VERSION.dup
end