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
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#singleton ⇒ Object
readonly
Returns the value of attribute singleton.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#covered? ⇒ Boolean
Marked as covered?.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(target, method, props = {}) ⇒ CoverUnit
constructor
A new instance of CoverUnit.
- #inspect ⇒ Object
-
#private? ⇒ Boolean
Method access is private or protected?.
- #singleton? ⇒ Boolean (also: #class_method?)
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(target, method, props = {}) ⇒ CoverUnit
Returns a new instance of CoverUnit.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lemon/coverage/cover_unit.rb', line 14 def initialize(target, method, props={}) @target = target @method = method.to_sym @covered = props[:covered] @singleton = props[:singleton] ? true : false if @singleton @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
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/lemon/coverage/cover_unit.rb', line 9 def method @method end |
#singleton ⇒ Object (readonly)
Returns the value of attribute singleton.
11 12 13 |
# File 'lib/lemon/coverage/cover_unit.rb', line 11 def singleton @singleton 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
90 91 92 93 94 95 96 |
# File 'lib/lemon/coverage/cover_unit.rb', line 90 def <=>(other) c = (target.name <=> other.target.name) return c unless c == 0 return -1 if singleton && !other.singleton return 1 if !singleton && other.singleton method.to_s <=> other.method.to_s end |
#covered? ⇒ Boolean
Marked as covered?
37 38 39 |
# File 'lib/lemon/coverage/cover_unit.rb', line 37 def covered? @covered end |
#eql?(other) ⇒ Boolean
72 73 74 75 76 77 78 |
# File 'lib/lemon/coverage/cover_unit.rb', line 72 def eql?(other) return false unless Unit === other return false unless target == other.target return false unless method == other.method return false unless singleton == other.singleton return true end |
#hash ⇒ Object
53 54 55 |
# File 'lib/lemon/coverage/cover_unit.rb', line 53 def hash @target.hash ^ @method.hash ^ singleton.hash end |
#inspect ⇒ Object
83 84 85 |
# File 'lib/lemon/coverage/cover_unit.rb', line 83 def inspect "#{target}#{singleton? ? '.' : '#'}#{method}" end |
#private? ⇒ Boolean
Method access is private or protected?
30 31 32 |
# File 'lib/lemon/coverage/cover_unit.rb', line 30 def private? @private end |
#singleton? ⇒ Boolean Also known as: class_method?
44 45 46 |
# File 'lib/lemon/coverage/cover_unit.rb', line 44 def singleton? @singleton end |
#to_s ⇒ Object Also known as: to_str
60 61 62 63 64 65 66 |
# File 'lib/lemon/coverage/cover_unit.rb', line 60 def to_s if singleton? "#{@target}.#{@method}" else "#{@target}##{@method}" end end |