Class: Lemon::CoverUnit
- Inherits:
-
Object
- Object
- Lemon::CoverUnit
- 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
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#covered? ⇒ Boolean
Marked as covered?.
- #eql?(other) ⇒ Boolean
- #function? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(target, method, props = {}) ⇒ CoverUnit
constructor
A new instance of CoverUnit.
- #inspect ⇒ Object
-
#private? ⇒ Boolean
Method access is private or protected?.
- #to_s ⇒ Object (also: #to_str)
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
#function ⇒ Object (readonly)
Returns the value of attribute function.
9 10 11 |
# File 'lib/lemon/coverage/cover_unit.rb', line 9 def function @function end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/lemon/coverage/cover_unit.rb', line 8 def method @method end |
#target ⇒ Object (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?
30 31 32 |
# File 'lib/lemon/coverage/cover_unit.rb', line 30 def covered? @covered end |
#eql?(other) ⇒ 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
35 36 37 |
# File 'lib/lemon/coverage/cover_unit.rb', line 35 def function? @function end |
#hash ⇒ Object
40 41 42 |
# File 'lib/lemon/coverage/cover_unit.rb', line 40 def hash @target.hash ^ @method.hash ^ @function.hash end |
#inspect ⇒ Object
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?
25 26 27 |
# File 'lib/lemon/coverage/cover_unit.rb', line 25 def private? @private end |
#to_s ⇒ Object 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 |