class Lemon::Snapshot

Snapshot is used to record the “unit picture” of the system at a given moment.

Attributes

units[R]

Public Class Methods

capture(namespaces=nil) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 10
def self.capture(namespaces=nil)
  o = new
  o.capture(namespaces)
  o
end
new(units=[]) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 20
def initialize(units=[])
  @units = units
end

Public Instance Methods

+(other) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 89
def +(other)
  Snapshot.new(units + other.units)
end
-(other) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 84
def -(other)
  Snapshot.new(units - other.units)
end
<<(other) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 94
def <<(other)
  @units.concat(other.units)
end
capture(namespaces=nil) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 45
def capture(namespaces=nil)
  @units = []
  ObjectSpace.each_object(Module) do |mod|
    next if mod.nil? or mod.name.nil? or mod.name.empty?
    #next if namespaces and !namespaces.any?{ |ns| /^#{ns}(::|$)/ =~ mod.to_s }
    next if namespaces and !namespaces.any?{ |ns| ns.to_s == mod.to_s }
    capture_namespace(mod)
  end
end
capture_namespace(mod) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 56
def capture_namespace(mod)
  ['', 'protected_', 'private_'].each do |access|
    methods  = mod.__send__("#{access}instance_methods", false)
    #methods -= Object.__send__("#{access}instance_methods", true)
    methods.each do |method|
      @units << Unit.new(mod, method, :access=>access)
    end

    methods  = mod.__send__("#{access}methods", false)
    #methods -= Object.__send__("#{access}methods", true)
    methods.each do |method|
      @units << Unit.new(mod, method, :access=>access, :singleton=>true)
    end
  end
  return @units
end
each(&block) click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 25
def each(&block)
  units.each(&block)
end
public_units() click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 79
def public_units
  @units.select{ |u| u.public? }
end
reset() click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 35
def reset
  each{ |u| u.covered = false }
end
size() click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 30
def size
  @units.size
end
to_a() click to toggle source
# File lib/lemon/coverage/snapshot.rb, line 74
def to_a
  @units
end