Class: Functional::Platform
Instance Attribute Summary collapse
-
#host_os ⇒ Object
readonly
Returns the value of attribute host_os.
-
#ruby_name ⇒ Object
readonly
Returns the value of attribute ruby_name.
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Platform
constructor
A new instance of Platform.
- #jruby? ⇒ Boolean
- #linux? ⇒ Boolean
- #mingw? ⇒ Boolean
- #mingw_18? ⇒ Boolean
- #mingw_19? ⇒ Boolean
- #mingw_20? ⇒ Boolean
- #mri? ⇒ Boolean
- #mri_18? ⇒ Boolean
- #mri_19? ⇒ Boolean
- #mri_20? ⇒ Boolean
- #mswin? ⇒ Boolean
- #osx? ⇒ Boolean
- #rbx? ⇒ Boolean
- #rubies ⇒ Object
- #ruby? ⇒ Boolean
- #ruby_18? ⇒ Boolean
- #ruby_19? ⇒ Boolean
- #ruby_20? ⇒ Boolean
- #windows? ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Platform
Returns a new instance of Platform.
30 31 32 33 34 35 36 37 38 |
# File 'lib/functional/platform.rb', line 30 def initialize(*args) unless args.size == 0 || args.size == 3 raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 or 3)") end @ruby_version = args[0] || RUBY_VERSION || RbConfig::CONFIG['ruby_version'] @host_os = args[1] || RbConfig::CONFIG['host_os'] @ruby_name = args[2] || RbConfig::CONFIG['ruby_install_name'] end |
Instance Attribute Details
#host_os ⇒ Object (readonly)
Returns the value of attribute host_os.
8 9 10 |
# File 'lib/functional/platform.rb', line 8 def host_os @host_os end |
#ruby_name ⇒ Object (readonly)
Returns the value of attribute ruby_name.
9 10 11 |
# File 'lib/functional/platform.rb', line 9 def ruby_name @ruby_name end |
#ruby_version ⇒ Object (readonly)
Returns the value of attribute ruby_version.
7 8 9 |
# File 'lib/functional/platform.rb', line 7 def ruby_version @ruby_version end |
Instance Method Details
#jruby? ⇒ Boolean
88 89 90 |
# File 'lib/functional/platform.rb', line 88 def jruby? truthy(@ruby_name =~ /^jruby$/i) end |
#linux? ⇒ Boolean
44 45 46 |
# File 'lib/functional/platform.rb', line 44 def linux? truthy(@host_os =~ /linux/i) end |
#mingw? ⇒ Boolean
96 97 98 |
# File 'lib/functional/platform.rb', line 96 def mingw? truthy(@host_os =~ /mingw32/i) end |
#mingw_18? ⇒ Boolean
100 101 102 |
# File 'lib/functional/platform.rb', line 100 def mingw_18? mingw? && truthy(@ruby_version =~ /^1\.8/) end |
#mingw_19? ⇒ Boolean
104 105 106 |
# File 'lib/functional/platform.rb', line 104 def mingw_19? mingw? && truthy(@ruby_version =~ /^1\.9/) end |
#mingw_20? ⇒ Boolean
108 109 110 |
# File 'lib/functional/platform.rb', line 108 def mingw_20? mingw? && truthy(@ruby_version =~ /^2\.0/) end |
#mri? ⇒ Boolean
68 69 70 |
# File 'lib/functional/platform.rb', line 68 def mri? truthy(@ruby_name =~ /^ruby$/i) && !windows? end |
#mri_18? ⇒ Boolean
72 73 74 |
# File 'lib/functional/platform.rb', line 72 def mri_18? mri? && truthy(@ruby_version =~ /^1\.8/) end |
#mri_19? ⇒ Boolean
76 77 78 |
# File 'lib/functional/platform.rb', line 76 def mri_19? mri? && truthy(@ruby_version =~ /^1\.9/) end |
#mri_20? ⇒ Boolean
80 81 82 |
# File 'lib/functional/platform.rb', line 80 def mri_20? mri? && truthy(@ruby_version =~ /^2\.0/) end |
#mswin? ⇒ Boolean
92 93 94 |
# File 'lib/functional/platform.rb', line 92 def mswin? truthy(@host_os =~ /win32/i) end |
#osx? ⇒ Boolean
48 49 50 |
# File 'lib/functional/platform.rb', line 48 def osx? truthy(@host_os =~ /darwin/i) end |
#rbx? ⇒ Boolean
84 85 86 |
# File 'lib/functional/platform.rb', line 84 def rbx? truthy(@ruby_name =~ /^rbx$/i) end |
#rubies ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/functional/platform.rb', line 11 def rubies @rubies ||= [ :ruby, # C Ruby (MRI) or Rubinius, but NOT Windows :ruby_18, # ruby AND version 1.8 :ruby_19, # ruby AND version 1.9 :mri, # Same as ruby, but not Rubinius :mri_18, # mri AND version 1.8 :mri_19, # mri AND version 1.9 :mri_20, # mri AND version 20 :rbx, # Same as ruby, but only Rubinius (not MRI) :jruby, # JRuby :mswin, # Windows :mingw, # Windows 'mingw32' platform (aka RubyInstaller) :mingw_18, # mingw AND version 1.8 :mingw_19, # mingw AND version 1.9 :mingw_20, # mingw AND version 2.0 ].freeze end |
#ruby? ⇒ Boolean
52 53 54 |
# File 'lib/functional/platform.rb', line 52 def ruby? mri? || rbx? end |
#ruby_18? ⇒ Boolean
56 57 58 |
# File 'lib/functional/platform.rb', line 56 def ruby_18? ruby? && truthy(@ruby_version =~ /^1\.8/) end |
#ruby_19? ⇒ Boolean
60 61 62 |
# File 'lib/functional/platform.rb', line 60 def ruby_19? ruby? && truthy(@ruby_version =~ /^1\.9/) end |
#ruby_20? ⇒ Boolean
64 65 66 |
# File 'lib/functional/platform.rb', line 64 def ruby_20? ruby? && truthy(@ruby_version =~ /^2\.0/) end |
#windows? ⇒ Boolean
40 41 42 |
# File 'lib/functional/platform.rb', line 40 def windows? truthy(@host_os =~ /win32/i) || truthy(@host_os =~ /mingw32/i) end |