Class: Mago::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/mago/detector.rb

Overview

Magic numbers detector.

Examples:

detector = Mago::Detector.new('./Rakefile', './lib')
detector.run # => #<Mago::Report ...>

Constant Summary collapse

DEFAULT_IGNORE =

Numbers which are ignored by default

[0, 1]

Instance Method Summary collapse

Constructor Details

#initialize(file_paths = [], options = {}) ⇒ Detector

Returns a new instance of Detector.

Parameters:

  • file_paths (String) (defaults to: [])

    ruby files

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :ignore (Array<Numeric>)

    numbers which must be ignored



15
16
17
18
19
# File 'lib/mago/detector.rb', line 15

def initialize(file_paths = [], options = {})
  @file_paths = file_paths
  @report = Report.new
  @ignore = options[:ignore] || DEFAULT_IGNORE
end

Instance Method Details

#on_error(&block) ⇒ Object

Set callback to be called when error occurs.



37
38
39
# File 'lib/mago/detector.rb', line 37

def on_error(&block)
  @on_error = block
end

#on_file(&block) ⇒ Object

Set callback to be called when file processing is finished.



32
33
34
# File 'lib/mago/detector.rb', line 32

def on_file(&block)
  @on_file = block
end

#runMago::Report

Process files and build a report.

Returns:



24
25
26
27
28
29
# File 'lib/mago/detector.rb', line 24

def run
  @file_paths.each do |path|
    process_file(path)
  end
  @report
end