lib/flay.rb in flay-1.2.0 vs lib/flay.rb in flay-1.2.1
- old
+ new
@@ -9,11 +9,11 @@
require 'ruby_parser'
abort "update rubygems to >= 1.3.1" unless Gem.respond_to? :find_files
class Flay
- VERSION = '1.2.0'
+ VERSION = '1.2.1'
def self.default_options
{
:fuzzy => false,
:verbose => false,
@@ -69,21 +69,24 @@
end
}.flatten
end
def self.load_plugins
- plugins = Gem.find_files("flay_*.rb").reject { |path| path =~ /flay_task/ }
+ unless defined? @@plugins then
+ plugins = Gem.find_files("flay_*.rb").reject { |p| p =~ /flay_task/ }
- plugins.each do |plugin|
- begin
- load plugin
- rescue LoadError => e
- warn "error loading #{plugin.inspect}: #{e.message}. skipping..."
+ plugins.each do |plugin|
+ begin
+ load plugin
+ rescue LoadError => e
+ warn "error loading #{plugin.inspect}: #{e.message}. skipping..."
+ end
end
- end
- plugins.map { |f| File.basename(f, '.rb').sub(/^flay_/, '') }
+ @@plugins = plugins.map { |f| File.basename(f, '.rb').sub(/^flay_/, '') }
+ end
+ @@plugins
end
attr_accessor :mass_threshold, :total, :identical, :masses
attr_reader :hashes, :option
@@ -97,11 +100,11 @@
self.mass_threshold = @option[:mass]
require 'ruby2ruby' if @option[:verbose]
end
- def process(*files)
+ def process(*files) # TODO: rename from process - should act as SexpProcessor
files.each do |file|
warn "Processing #{file}"
ext = File.extname(file).sub(/^\./, '')
ext = "rb" if ext.nil? || ext.empty?
@@ -125,9 +128,13 @@
process_sexp sexp
end
process_fuzzy_similarities if option[:fuzzy]
+ analyze
+ end
+
+ def analyze
self.prune
self.hashes.each do |hash,nodes|
identical[hash] = nodes[1..-1].all? { |n| n == nodes.first }
masses[hash] = nodes.first.mass * nodes.size