Class: Functional::Platform

Inherits:
Object show all
Defined in:
lib/functional/platform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_osObject (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_nameObject (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_versionObject (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

Returns:

  • (Boolean)


88
89
90
# File 'lib/functional/platform.rb', line 88

def jruby?
  truthy(@ruby_name =~ /^jruby$/i)
end

#linux?Boolean

Returns:

  • (Boolean)


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

def linux?
  truthy(@host_os =~ /linux/i)
end

#mingw?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/functional/platform.rb', line 96

def mingw?
  truthy(@host_os =~ /mingw32/i)
end

#mingw_18?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/functional/platform.rb', line 100

def mingw_18?
  mingw? && truthy(@ruby_version =~ /^1\.8/)
end

#mingw_19?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/functional/platform.rb', line 104

def mingw_19?
  mingw? && truthy(@ruby_version =~ /^1\.9/)
end

#mingw_20?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/functional/platform.rb', line 108

def mingw_20?
  mingw? && truthy(@ruby_version =~ /^2\.0/)
end

#mri?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/functional/platform.rb', line 68

def mri?
  truthy(@ruby_name =~ /^ruby$/i) && !windows?
end

#mri_18?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/functional/platform.rb', line 72

def mri_18?
  mri? && truthy(@ruby_version =~ /^1\.8/)
end

#mri_19?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/functional/platform.rb', line 76

def mri_19?
  mri? && truthy(@ruby_version =~ /^1\.9/)
end

#mri_20?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/functional/platform.rb', line 80

def mri_20?
  mri? && truthy(@ruby_version =~ /^2\.0/)
end

#mswin?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/functional/platform.rb', line 92

def mswin?
  truthy(@host_os =~ /win32/i)
end

#osx?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/functional/platform.rb', line 48

def osx?
  truthy(@host_os =~ /darwin/i)
end

#rbx?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/functional/platform.rb', line 84

def rbx?
  truthy(@ruby_name =~ /^rbx$/i)
end

#rubiesObject



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

Returns:

  • (Boolean)


52
53
54
# File 'lib/functional/platform.rb', line 52

def ruby?
  mri? || rbx?
end

#ruby_18?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/functional/platform.rb', line 56

def ruby_18?
  ruby? && truthy(@ruby_version =~ /^1\.8/)
end

#ruby_19?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/functional/platform.rb', line 60

def ruby_19?
  ruby? && truthy(@ruby_version =~ /^1\.9/)
end

#ruby_20?Boolean

Returns:

  • (Boolean)


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

def ruby_20?
  ruby? && truthy(@ruby_version =~ /^2\.0/)
end

#windows?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/functional/platform.rb', line 40

def windows?
  truthy(@host_os =~ /win32/i) || truthy(@host_os =~ /mingw32/i)
end