lib/flay.rb in flay-2.10.0 vs lib/flay.rb in flay-2.11.0
- old
+ new
@@ -4,21 +4,22 @@
require "rubygems"
require "sexp_processor"
require "ruby_parser"
require "path_expander"
require "timeout"
+require "zlib"
class File
RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19 # :nodoc:
class << self
alias :binread :read unless RUBY19
end
end
class Flay
- VERSION = "2.10.0" # :nodoc:
+ VERSION = "2.11.0" # :nodoc:
class Item < Struct.new(:structural_hash, :name, :bonus, :mass, :locations)
alias identical? bonus
end
@@ -49,11 +50,12 @@
:verbose => false,
:number => true,
:timeout => 10,
:liberal => false,
:fuzzy => false,
- :only => nil,
+ :only => nil,
+ :filters => [],
}
end
##
# Process options in +args+, defaulting to +ARGV+.
@@ -167,12 +169,12 @@
# :startdoc:
##
# Create a new instance of Flay with +option+s.
- def initialize option = nil
- @option = option || Flay.default_options
+ def initialize option = {}
+ @option = Flay.default_options.merge option
@hashes = Hash.new { |h,k| h[k] = [] }
self.identical = {}
self.masses = {}
self.total = 0
@@ -281,12 +283,13 @@
##
# Process a sexp +pt+.
def process_sexp pt
pt.deep_each do |node|
- next unless node.any? { |sub| Sexp === sub }
- next if node.mass < self.mass_threshold
+ next :skip if node.none? { |sub| Sexp === sub }
+ next :skip if node.mass < self.mass_threshold
+ next :skip if option[:filters].any? { |pattern| pattern.satisfy? node }
self.hashes[node.structural_hash] << node
process_fuzzy node, option[:fuzzy] if option[:fuzzy]
end
@@ -630,29 +633,10 @@
self.split_at index if index
end
end
class Sexp # straight from flay-persistent
- names = %w(alias and arglist args array attrasgn attrset back_ref
- begin block block_pass break call case cdecl class colon2
- colon3 const cvar cvasgn cvdecl defined defn defs dot2
- dot3 dregx dregx_once dstr dsym dxstr ensure evstr false
- flip2 flip3 for gasgn gvar hash iasgn if iter ivar lasgn
- lit lvar masgn match match2 match3 module next nil not
- nth_ref op_asgn op_asgn1 op_asgn2 op_asgn_and op_asgn_or or
- postexe redo resbody rescue retry return sclass self
- splat str super svalue to_ary true undef until valias
- when while xstr yield zsuper kwarg kwsplat safe_call)
-
- ##
- # All ruby_parser nodes in an index hash. Used by jenkins algorithm.
-
- NODE_NAMES = Hash[names.each_with_index.map {|n, i| [n.to_sym, i] }]
-
- NODE_NAMES.default_proc = lambda { |h, k|
- $stderr.puts "ERROR: couldn't find node type #{k} in Sexp::NODE_NAMES."
- h[k] = NODE_NAMES.size
- }
+ NODE_NAMES = Hash.new { |h,k| h[k] = Zlib.crc32(k.to_s) }
MAX_INT32 = 2 ** 32 - 1 # :nodoc:
def pure_ruby_hash # :nodoc: see above
hash = 0