Class: Lemon::SourceParser::Scope

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/lemon/coverage/source_parser.rb

Overview

A Scope is a Module or Class, and may contain other scopes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, comment = '', instance_methods = [], class_methods = []) ⇒ Scope

Returns a new instance of Scope.



184
185
186
187
188
189
190
# File 'lib/lemon/coverage/source_parser.rb', line 184

def initialize(name, comment='', instance_methods=[], class_methods=[])
  @name             = name
  @comment          = comment
  @instance_methods = instance_methods
  @class_methods    = class_methods
  @scopes           = {}
end

Instance Attribute Details

#class_methodsObject

Returns the value of attribute class_methods.



178
179
180
# File 'lib/lemon/coverage/source_parser.rb', line 178

def class_methods
  @class_methods
end

#commentObject

Returns the value of attribute comment.



178
179
180
# File 'lib/lemon/coverage/source_parser.rb', line 178

def comment
  @comment
end

#instance_methodsObject

Returns the value of attribute instance_methods.



178
179
180
# File 'lib/lemon/coverage/source_parser.rb', line 178

def instance_methods
  @instance_methods
end

#nameObject

Returns the value of attribute name.



178
179
180
# File 'lib/lemon/coverage/source_parser.rb', line 178

def name
  @name
end

#parentObject

Returns the value of attribute parent.



180
181
182
# File 'lib/lemon/coverage/source_parser.rb', line 180

def parent
  @parent
end

#scopesObject

Returns the value of attribute scopes.



182
183
184
# File 'lib/lemon/coverage/source_parser.rb', line 182

def scopes
  @scopes
end

Instance Method Details

#[](scope) ⇒ Object



192
193
194
# File 'lib/lemon/coverage/source_parser.rb', line 192

def [](scope)
  @scopes[scope]
end

#each(&block) ⇒ Object



200
201
202
# File 'lib/lemon/coverage/source_parser.rb', line 200

def each(&block)
  @scopes.each(&block)
end

#inspectObject



208
209
210
211
212
213
214
# File 'lib/lemon/coverage/source_parser.rb', line 208

def inspect
  scopes   = @scopes.keys.join(', ')
  imethods = @instance_methods.inspect
  cmethods = @class_methods.inspect

  "<#{name} scopes:[#{scopes}] :#{cmethods}: ##{imethods}#>"
end

#keysObject



196
197
198
# File 'lib/lemon/coverage/source_parser.rb', line 196

def keys
  @scopes.keys
end

#targetObject



217
218
219
220
221
222
223
# File 'lib/lemon/coverage/source_parser.rb', line 217

def target
  if parent
    parent.target.const_get(name)
  else
    Object.const_get(name)
  end
end

#to_sObject



204
205
206
# File 'lib/lemon/coverage/source_parser.rb', line 204

def to_s
  inspect
end

#to_unitsObject



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/lemon/coverage/source_parser.rb', line 226

def to_units
  units = []
  @instance_methods.each do |imethod|
    units << Snapshot::Unit.new(target, imethod, :singleton=>false)
  end
  @class_methods.each do |imethod|
    units << Snapshot::Unit.new(target, imethod, :singleton=>true)
  end
  @scopes.each do |name, scope|
    units.concat(scope.to_units)
  end
  units
end