Module: Toki

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

Constant Summary collapse

VERSION =
File.read(File.expand_path('../../../version', __FILE__))

Instance Method Summary collapse

Instance Method Details

#when_ironruby_version(value, &block) ⇒ Object

IRONRUBY_VERSION



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/toki.rb', line 93

def when_ironruby_version(value, &block)
  if defined?(IRONRUBY_VERSION)
    if value_matches_with?(value, IRONRUBY_VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # IRONRUBY_VERSION not defined
    false
  end
end

#when_jruby_version(value, &block) ⇒ Object

JRUBY_VERSION



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/toki.rb', line 37

def when_jruby_version(value, &block)
  if defined?(JRUBY_VERSION)
    if value_matches_with?(value, JRUBY_VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # JRUBY_VERSION not defined
    false
  end
end

#when_kiji_version(value, &block) ⇒ Object

KIJI_VERSION



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/toki.rb', line 107

def when_kiji_version(value, &block)
  if defined?(KIJI_VERSION)
    if value_matches_with?(value, KIJI_VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # KIJI_VERSION not defined
    false
  end
end

#when_macruby_version(value, &block) ⇒ Object

MACRUBY_VERSION



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/toki.rb', line 51

def when_macruby_version(value, &block)
  if defined?(MACRUBY_VERSION)
    if value_matches_with?(value, MACRUBY_VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # MACRUBY_VERSION not defined
    false
  end
end

#when_maglev_version(value, &block) ⇒ Object

MAGLEV_VERSION



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/toki.rb', line 79

def when_maglev_version(value, &block)
  if defined?(MAGLEV_VERSION)
    if value_matches_with?(value, MAGLEV_VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # MAGLEV_VERSION not defined
    false
  end
end

#when_platform(value, &block) ⇒ Object

RUBY_PLATFORM



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/toki.rb', line 150

def when_platform(value, &block)
  case value
  when Symbol
    if value == detect_os
      apply_behaviour(&block)
    else
      false
    end
  else
    if value_matches_with?(value, RbConfig::CONFIG['host_os'])
      apply_behaviour(&block)
    else
      false
    end
  end
end

#when_rbx_version(value, &block) ⇒ Object

Rubinius::VERSION



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/toki.rb', line 65

def when_rbx_version(value, &block)
  if defined?(Rubinius)
    if value_matches_with?(value, Rubinius::VERSION)
      apply_behaviour(&block)
    else
      false
    end
  else
    # Rubinius not defined
    false
  end
end

#when_ruby(options, &block) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/toki.rb', line 6

def when_ruby(options, &block)
  raise ArgumentError, "wrong argument type #{options.class} (expected Hash)" unless options.kind_of?(Hash)
  apply_behaviour(&block) if options.all? do | key, value |
    case key
    when :version
      when_ruby_version(value)
    when :jruby_version
      when_jruby_version(value)
    when :macruby_version
      when_macruby_version(value)
    when :rbx_version
      when_rbx_version(value)
    when :maglev_version
      when_maglev_version(value)
    when :ironruby_version
      when_ironruby_version(value)
    when :kiji_version
      when_kiji_version(value)
    when :engine
      when_ruby_engine(value)
    when :patchlevel
      when_ruby_patchlevel(value)
    when :platform
      when_platform(value)
    else
      raise ArgumentError, "unsupported key #{key} for when_ruby options"
    end
  end
end

#when_ruby_engine(value, &block) ⇒ Object

RUBY_ENGINE



139
140
141
142
143
144
145
146
147
# File 'lib/toki.rb', line 139

def when_ruby_engine(value, &block)
  # ruby 1.8.7 does not have RUBY_ENGINE constant
  ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
  if value_matches_with?(value, ruby_engine)
    apply_behaviour(&block)
  else
    false
  end
end

#when_ruby_patchlevel(value, &block) ⇒ Object

RUBY_PATCHLEVEL



130
131
132
133
134
135
136
# File 'lib/toki.rb', line 130

def when_ruby_patchlevel(value, &block)
  if value_matches_with?(value, RUBY_PATCHLEVEL)
    apply_behaviour(&block)
  else
    false
  end
end

#when_ruby_version(value, &block) ⇒ Object

RUBY_VERSION



121
122
123
124
125
126
127
# File 'lib/toki.rb', line 121

def when_ruby_version(value, &block)
  if value_matches_with?(value, RUBY_VERSION)
    apply_behaviour(&block)
  else
    false
  end
end