lib/flay.rb in flay-2.7.0 vs lib/flay.rb in flay-2.8.0
- old
+ new
@@ -2,10 +2,11 @@
require "optparse"
require "rubygems"
require "sexp_processor"
require "ruby_parser"
+require "path_expander"
require "timeout"
class File
RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19 # :nodoc:
@@ -13,20 +14,32 @@
alias :binread :read unless RUBY19
end
end
class Flay
- VERSION = "2.7.0" # :nodoc:
+ VERSION = "2.8.0" # :nodoc:
class Item < Struct.new(:structural_hash, :name, :bonus, :mass, :locations)
alias identical? bonus
end
class Location < Struct.new(:file, :line, :fuzzy)
alias fuzzy? fuzzy
end
+ def self.run args = ARGV
+ extensions = ["rb"] + Flay.load_plugins
+ glob = "**/*.{#{extensions.join ","}}"
+
+ expander = PathExpander.new args, glob
+ files = expander.filter_files expander.process, DEFAULT_IGNORE
+
+ flay = Flay.new Flay.parse_options args
+ flay.process(*files)
+ flay
+ end
+
##
# Returns the default options.
def self.default_options
{
@@ -118,61 +131,11 @@
end
options
end
- ##
- # Expands +*dirs+ to all files within that match ruby and rake extensions.
- # --
- # REFACTOR: from flog
-
- def self.expand_dirs_to_files *dirs
- extensions = ["rb"] + Flay.load_plugins
-
- dirs.flatten.map { |p|
- if File.directory? p then
- Dir[File.join(p, "**", "*.{#{extensions.join(",")}}")]
- else
- p
- end
- }.flatten.map { |s| s.sub(/^\.\//, "") } # strip "./" from paths
- end
-
# so I can move this to flog wholesale
DEFAULT_IGNORE = ".flayignore" # :nodoc:
-
- ##
- # A file filter mechanism similar to, but not as extensive as,
- # .gitignore files:
- #
- # + If a pattern does not contain a slash, it is treated as a shell glob.
- # + If a pattern ends in a slash, it matches on directories (and contents).
- # + Otherwise, it matches on relative paths.
- #
- # File.fnmatch is used throughout, so glob patterns work for all 3 types.
-
- def self.filter_files files, ignore = DEFAULT_IGNORE
- ignore_paths = if ignore.respond_to? :read then
- ignore.read
- elsif File.exists? ignore then
- File.read ignore
- end
-
- if ignore_paths then
- nonglobs, globs = ignore_paths.split("\n").partition { |p| p.include? "/" }
- dirs, ifiles = nonglobs.partition { |p| p.end_with? "/" }
- dirs = dirs.map { |s| s.chomp "/" }
-
- only_paths = File::FNM_PATHNAME
- files = files.reject { |f|
- dirs.any? { |i| File.fnmatch?(i, File.dirname(f), only_paths) } ||
- globs.any? { |i| File.fnmatch?(i, f) } ||
- ifiles.any? { |i| File.fnmatch?(i, f, only_paths) }
- }
- end
-
- files
- end
##
# Loads all flay plugins. Files must be named "flay_*.rb".
def self.load_plugins