Class: Lemon::CoverUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/lemon/coverage/cover_unit.rb

Overview

Unit of coverage, ecapsulates a method, it’s characteristics and a flag as to whether it has been covered or not.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, method, props = {}) ⇒ CoverUnit

Returns a new instance of CoverUnit.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lemon/coverage/cover_unit.rb', line 11

def initialize(target, method, props={})
  @target   = target
  @method   = method.to_sym
  @function = props[:function] ? true : false
  @covered  = props[:covered]

  if @function
    @private = !@target.public_methods.find{ |m| m.to_sym == @method }
  else
    @private = !@target.public_instance_methods.find{ |m| m.to_sym == @method }
  end
end

Instance Attribute Details

#functionObject (readonly)

Returns the value of attribute function.



9
10
11
# File 'lib/lemon/coverage/cover_unit.rb', line 9

def function
  @function
end

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/lemon/coverage/cover_unit.rb', line 8

def method
  @method
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/lemon/coverage/cover_unit.rb', line 7

def target
  @target
end

Instance Method Details

#<=>(other) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/lemon/coverage/cover_unit.rb', line 66

def <=>(other)
  c = (target.name <=> other.target.name)
  return c unless c == 0
  return -1 if function  && !other.function
  return  1 if !function && other.function
  method.to_s <=> other.method.to_s
end

#covered?Boolean

Marked as covered?

Returns:

  • (Boolean)


30
31
32
# File 'lib/lemon/coverage/cover_unit.rb', line 30

def covered?
  @covered
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/lemon/coverage/cover_unit.rb', line 54

def eql?(other)
  return false unless Unit === other
  return false unless target == other.target
  return false unless method == other.method
  return false unless function == other.function
  return true
end

#function?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/lemon/coverage/cover_unit.rb', line 35

def function?
  @function
end

#hashObject



40
41
42
# File 'lib/lemon/coverage/cover_unit.rb', line 40

def hash
  @target.hash ^ @method.hash ^ @function.hash
end

#inspectObject



62
63
64
# File 'lib/lemon/coverage/cover_unit.rb', line 62

def inspect
  "#{target}#{function ? '.' : '#'}#{method}"
end

#private?Boolean

Method access is private or protected?

Returns:

  • (Boolean)


25
26
27
# File 'lib/lemon/coverage/cover_unit.rb', line 25

def private?
  @private
end

#to_sObject Also known as: to_str



45
46
47
48
49
50
51
# File 'lib/lemon/coverage/cover_unit.rb', line 45

def to_s
  if @function
    "#{@target}.#{@method}"
  else
    "#{@target}##{@method}"
  end
end