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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ RSpecVersion

Returns a new instance of RSpecVersion.



28
29
30
31
32
33
34
# File 'lib/transpec/rspec_version.rb', line 28

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.



11
12
13
# File 'lib/transpec/rspec_version.rb', line 11

def gem_version
  @gem_version
end

Class Method Details

.define_feature(feature, version_string, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/transpec/rspec_version.rb', line 13

def self.define_feature(feature, version_string, options = {})
  available_version = new(version_string)

  exception_version_strings = Array(options[:except])
  exception_versions = exception_version_strings.map { |s| new(s) }

  define_singleton_method("#{feature}_available_version") do
    available_version
  end

  define_method("#{feature}_available?") do
    self >= available_version && !exception_versions.include?(self)
  end
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#to_sObject



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

def to_s
  @gem_version.to_s
end