class ZombieScout::Mission

Attributes

defined_method_count[R]

Public Class Methods

new(globs) click to toggle source
# File lib/zombie_scout/mission.rb, line 11
def initialize(globs)
  @ruby_project = RubyProject.new(*globs)
  @whitelist = Whitelist.new
end

Public Instance Methods

duration() click to toggle source
# File lib/zombie_scout/mission.rb, line 30
def duration
  @end_time - @start_time
end
scout() click to toggle source
# File lib/zombie_scout/mission.rb, line 16
def scout
  @start_time = Time.now
  zombies.map { |zombie|
    { location: zombie.location,
      file_path: zombie.file_path,
      name: zombie.name,
      full_name: zombie.full_name,
      flog_score: flog_score(zombie)
    }
  }.tap {
    @end_time = Time.now
  }
end
source_count() click to toggle source
# File lib/zombie_scout/mission.rb, line 34
def source_count
  sources.size
end
zombie_count() click to toggle source
# File lib/zombie_scout/mission.rb, line 38
def zombie_count
  zombies.size
end

Private Instance Methods

flog_score(zombie) click to toggle source
# File lib/zombie_scout/mission.rb, line 48
def flog_score(zombie)
  ZombieScout::FlogScorer.new(zombie).score
end
might_be_dead?(method) click to toggle source
# File lib/zombie_scout/mission.rb, line 78
def might_be_dead?(method)
  unless whitelisted?(method)
    @method_call_counter ||= MethodCallFinder.new(@ruby_project)
    @method_call_counter.count_calls(method.name) < 2
  end
end
scout!() click to toggle source
# File lib/zombie_scout/mission.rb, line 61
def scout!
  @defined_methods, @called_methods = [], []

  sources.each do |ruby_source|
    parser = ZombieScout::Parser.new(ruby_source)
    @defined_methods.concat(parser.defined_methods)
    @called_methods.concat(parser.called_methods)
  end

  @defined_method_count = @defined_methods.size

  @called_methods.uniq!
  @defined_methods.reject! do |method|
    @called_methods.include?(method.name)
  end
end
sources() click to toggle source
# File lib/zombie_scout/mission.rb, line 44
def sources
  @sources ||= @ruby_project.ruby_sources
end
whitelisted?(method) click to toggle source
# File lib/zombie_scout/mission.rb, line 85
def whitelisted?(method)
  @whitelist.include?(method.full_name)
end
zombies() click to toggle source
# File lib/zombie_scout/mission.rb, line 52
def zombies
  return @zombies unless @zombies.nil?

  scout!
  @zombies = @defined_methods.select { |method|
    might_be_dead?(method)
  }
end