Class: Transpec::RSpecVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/transpec/rspec_version.rb

Overview

Gem::Version caches its instances with class variable @@all, so we should not inherit it.

Constant Summary collapse

GEM_VERSION_2_99 =

www.ruby-doc.org/stdlib-2.0.0/libdoc/rubygems/rdoc/Gem/Version.html

If any part contains letters (currently only a-z are supported) then that version is considered prerelease. Prerelease parts are sorted alphabetically using the normal Ruby string sorting rules. If a prerelease part contains both letters and numbers, it will be broken into multiple parts to provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is greater than 1.0.a9).

Gem::Version.new('2.99.aaaaaaaaaa')
GEM_VERSION_3_0 =
Gem::Version.new('3.0.aaaaaaaaaa')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ RSpecVersion

Returns a new instance of RSpecVersion.



23
24
25
26
27
28
29
# File 'lib/transpec/rspec_version.rb', line 23

def initialize(version)
  @gem_version = if version.is_a?(Gem::Version)
                   version
                 else
                   Gem::Version.new(version)
                 end
end

Instance Attribute Details

#gem_versionObject (readonly)

Returns the value of attribute gem_version.



21
22
23
# File 'lib/transpec/rspec_version.rb', line 21

def gem_version
  @gem_version
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/transpec/rspec_version.rb', line 39

def <=>(other)
  @gem_version <=> other.gem_version
end

#be_truthy_available?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/transpec/rspec_version.rb', line 31

def be_truthy_available?
  @gem_version >= GEM_VERSION_2_99
end

#receive_messages_available?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/transpec/rspec_version.rb', line 35

def receive_messages_available?
  @gem_version >= GEM_VERSION_3_0
end

#to_sObject



43
44
45
# File 'lib/transpec/rspec_version.rb', line 43

def to_s
  @gem_version.to_s
end