Class: VersionGuard
Instance Method Summary
collapse
Methods inherited from SpecGuard
#===, #after, #before, finish, #implementation?, #os?, #platform?, register, #unregister, unregister, #windows?, #wordsize?, #yield?
Constructor Details
Returns a new instance of VersionGuard.
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/mspec/guards/version.rb', line 4
def initialize(version)
case version
when String
@version = to_v version
when Range
a = to_v version.first
b = to_v version.last
@version = version.exclude_end? ? a...b : a..b
end
end
|
Instance Method Details
#match? ⇒ Boolean
24
25
26
27
28
29
30
31
|
# File 'lib/mspec/guards/version.rb', line 24
def match?
case @version
when Integer
ruby_version >= @version
when Range
@version.include? ruby_version
end
end
|
#ruby_version ⇒ Object
20
21
22
|
# File 'lib/mspec/guards/version.rb', line 20
def ruby_version
to_v("#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}")
end
|
#to_v(str) ⇒ Object
15
16
17
18
|
# File 'lib/mspec/guards/version.rb', line 15
def to_v(str)
major, minor, tiny, patch = str.split "."
("1%02d%02d%02d%04d" % [major, minor, tiny, patch].map { |x| x.to_i }).to_i
end
|