Skip to content

Commit

Permalink
specify callback and filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
franzk committed Jul 12, 2012
1 parent e80990a commit 4ec1dab
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/em-fs/dir/glob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ class Glob

def initialize pattern
@weight = nil
@type = nil
@callback = proc{}
parse pattern
end

def callback &block
@callback = block
end

def parse pattern
root = []

Expand All @@ -34,12 +40,17 @@ def parse pattern

def each options = {}, &block
options = {
depth: :inf
depth: :inf,
type: :all
}.merge options

EM::SystemCommand.execute find_command(options) do |on|
on.stdout.line do |line|
block.call File::Stat.parse line
end
on.success do
@callback.call
end
end
end

Expand All @@ -64,14 +75,16 @@ def each_path options = {}, &block
private
def find_command options = {}
options = {
depth: (@weight || :inf)
depth: (@weight || :inf),
type: (@type || :all)
}.merge options

builder = EM::SystemCommand::Builder.new 'find'
builder << @root
builder << [ :path, @path ] unless @path == "*" or @path == ''
builder << [ :name, @name ] unless @name == "*"
builder << [ :maxdepth, options[:depth] ] unless options[:depth] == :inf
builder << [ :type, options[:type] ] unless options[:type] == :all
builder << [ :printf, FORMAT ]
builder.to_s.gsub(/-+(\w)/, "-\\1")
end
Expand Down

0 comments on commit 4ec1dab

Please sign in to comment.