Class: Lemon::Snapshot::Unit
- Inherits:
-
Object
- Object
- Lemon::Snapshot::Unit
- Defined in:
- lib/lemon/coverage/snapshot.rb
Overview
Snapshot Unit encapsulates a method and it’s various characteristics.
Instance Attribute Summary collapse
-
#covered ⇒ Object
Can be used to flag a unit as covered.
-
#method ⇒ Object
readonly
Method name.
-
#singleton ⇒ Object
readonly
Is the method a “class method”, rather than an instance method.
-
#target ⇒ Object
readonly
Clsss or module.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #access ⇒ Object
-
#covered? ⇒ Boolean
Marked as covered?.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(target, method, props = {}) ⇒ Unit
constructor
A new instance of Unit.
- #inspect ⇒ Object
-
#namespace ⇒ Object
Alternate name for target.
-
#private? ⇒ Boolean
Method access is public?.
- #protected? ⇒ Boolean
-
#public? ⇒ Boolean
Method access is public?.
- #singleton? ⇒ Boolean
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(target, method, props = {}) ⇒ Unit
Returns a new instance of Unit.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/lemon/coverage/snapshot.rb', line 110 def initialize(target, method, props={}) @target = target @method = method.to_sym @singleton = props[:singleton] ? true : false @covered = props[:covered] if @singleton @private = @target.private_methods.find{ |m| m.to_sym == @method } @protected = @target.protected_methods.find{ |m| m.to_sym == @method } else @private = @target.private_instance_methods.find{ |m| m.to_sym == @method } @protected = @target.protected_instance_methods.find{ |m| m.to_sym == @method } end end |
Instance Attribute Details
#covered ⇒ Object
Can be used to flag a unit as covered.
126 127 128 |
# File 'lib/lemon/coverage/snapshot.rb', line 126 def covered @covered end |
#method ⇒ Object (readonly)
Method name.
105 106 107 |
# File 'lib/lemon/coverage/snapshot.rb', line 105 def method @method end |
#singleton ⇒ Object (readonly)
Is the method a “class method”, rather than an instance method.
108 109 110 |
# File 'lib/lemon/coverage/snapshot.rb', line 108 def singleton @singleton end |
#target ⇒ Object (readonly)
Clsss or module.
102 103 104 |
# File 'lib/lemon/coverage/snapshot.rb', line 102 def target @target end |
Instance Method Details
#<=>(other) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/lemon/coverage/snapshot.rb', line 192 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 |
#access ⇒ Object
154 155 156 157 158 |
# File 'lib/lemon/coverage/snapshot.rb', line 154 def access return :private if private? return :protected if protected? :public end |
#covered? ⇒ Boolean
Marked as covered?
161 162 163 |
# File 'lib/lemon/coverage/snapshot.rb', line 161 def covered? @covered end |
#eql?(other) ⇒ Boolean
180 181 182 183 184 185 186 |
# File 'lib/lemon/coverage/snapshot.rb', line 180 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
166 167 168 |
# File 'lib/lemon/coverage/snapshot.rb', line 166 def hash @target.hash ^ @method.hash ^ @singleton.hash end |
#inspect ⇒ Object
188 189 190 |
# File 'lib/lemon/coverage/snapshot.rb', line 188 def inspect "#{target}#{singleton ? '.' : '#'}#{method}" end |
#namespace ⇒ Object
Alternate name for target.
129 130 131 |
# File 'lib/lemon/coverage/snapshot.rb', line 129 def namespace @target end |
#private? ⇒ Boolean
Method access is public?
144 145 146 |
# File 'lib/lemon/coverage/snapshot.rb', line 144 def private? @private end |
#protected? ⇒ Boolean
149 150 151 |
# File 'lib/lemon/coverage/snapshot.rb', line 149 def protected? @protected end |
#public? ⇒ Boolean
Method access is public?
139 140 141 |
# File 'lib/lemon/coverage/snapshot.rb', line 139 def public? !(@private or @protected) end |
#singleton? ⇒ Boolean
134 135 136 |
# File 'lib/lemon/coverage/snapshot.rb', line 134 def singleton? @singleton end |
#to_s ⇒ Object Also known as: to_str
171 172 173 174 175 176 177 |
# File 'lib/lemon/coverage/snapshot.rb', line 171 def to_s if @singleton "#{@target}.#{@method}" else "#{@target}##{@method}" end end |