Top Level Namespace

Defined Under Namespace

Modules: SantasLittleHelper

Instance Method Summary collapse

Instance Method Details

#jruby?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/santas_little_helper.rb', line 64

def jruby?
  ruby_implementation?(:jruby)
end

#linux?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/santas_little_helper.rb', line 44

def linux?
  ruby_platform?(:linux)
end

#mac?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/santas_little_helper.rb', line 47

def mac?
  ruby_platform?(:mac)
end

#mri?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/santas_little_helper.rb', line 67

def mri?
  ruby_implementation?(:mri)
end

#ruby_implementationObject

I test and deploy some of the project on jruby - this makes it easier to customize my gemfiles. Works for ruby 1.8.7 & 1.9.3 & 1.9.2 on windows( 7 & xp) & linux ( debian Lenny) using rubyinstaller for windows and using mri ruby buillt from source for linux Works for jruby 1.7.0.rc1 and jruby 1.6.3 on windows (7 & xp) At this point it’s essentially just an alias fro platform & platform?, since it queries RUBY_PLATFORM, but this may change in the future In the future I may start using RUBY_ENGINE



58
59
60
# File 'lib/santas_little_helper.rb', line 58

def ruby_implementation
  ruby_platform
end

#ruby_implementation?(written_in = '') ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/santas_little_helper.rb', line 61

def ruby_implementation?(written_in='')
  ruby_platform?(written_in)
end

#ruby_platformObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/santas_little_helper.rb', line 13

def ruby_platform
  case RUBY_PLATFORM
    when /win32|mswin|mingw/
      # Works on Windows XP, 2003, 7, 8 running Ruby 1.8.6 & 1.8.7, 1.9.2, 1.9.3 & 2.0.0 installed from RubyInstaller
      # Can't match for just 'win' cause it will match darwin as well.
      'windows'
    when /linux/
      # Works on Debian Sarge, Lenny & Wheezy and Ubuntu 9.10 running REE 1.8.7 & MRI 2.0.0 32-bit & 64-bit, don't have anything else to test on.
      'linux'
    when /darwin/
      # Works on my MacBook Pro OS 10.6 running Ruby 1.8.7 and .rbenv version of 1.9.3 & 2.0.0 , don't have anything else to test on,
      'mac'
    when /java/
      'jruby'
    when /i386|x86_64|x86/
      # I'm actually not sure what rubinius or maglev or other implementions would return. I don't rubies, other than mri or jruby.
      'mri'
    else
      nil
  end
end

#ruby_platform?(os = '') ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/santas_little_helper.rb', line 35

def ruby_platform?(os='')
  # Takes a string or a method like so platform?(:windows)
  os.to_s.match(ruby_platform) ? true : false
end

#ruby_versionObject

In case ruby ever reaches version 19 :-) or some 2.19 :-) only matching 1.9 at the begining of the line Returns an integer for easy version comparison 200 > 187 ( Version two is newer :-) ) if ruby_version > 187 , install new version of the gem.



75
76
77
# File 'lib/santas_little_helper.rb', line 75

def ruby_version
  RUBY_VERSION.gsub(/[^0-9]/,'').to_i
end

#ruby_version?(version_to_check) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
# File 'lib/santas_little_helper.rb', line 78

def ruby_version?(version_to_check)
  # Be careful - this will only match up to minor release. It will not match patch versions.
  # You can ask it things in the following formats ruby_version?(1), ruby_version?(1.8), ruby_version?('200')
  version_to_check = version_to_check.to_s.gsub(/[^0-9]/,'')
  RUBY_VERSION.gsub(/[^0-9]/,'')[0..(version_to_check.size-1)] == version_to_check[0..(version_to_check.size-1)]
end

#windows?Boolean

These are just aliases for convinience, I really doubt somebody would use them System Wide on an object for any other purpose.

Returns:

  • (Boolean)


41
42
43
# File 'lib/santas_little_helper.rb', line 41

def windows?
  ruby_platform?(:windows)
end