Module: PatchLife

Defined in:
lib/version.rb,
lib/patch_life.rb

Defined Under Namespace

Modules: Version

Class Method Summary collapse

Class Method Details

.define_patch_life(options = {}, &blk) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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_levelObject



24
25
26
# File 'lib/patch_life.rb', line 24

def ruby_patch_level
  RUBY_PATCHLEVEL
end

.ruby_versionObject



19
20
21
# File 'lib/patch_life.rb', line 19

def ruby_version
  RUBY_VERSION.dup
end