Class: EventMachine::Dir::Glob

Inherits:
Object
  • Object
show all
Defined in:
lib/em-fs/dir/glob.rb

Constant Summary collapse

FORMAT =
"%m %D '%y' %G %n %i '%p' %s %U %A@ %T@ %C@\\n"

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Glob

Returns a new instance of Glob.



7
8
9
10
# File 'lib/em-fs/dir/glob.rb', line 7

def initialize pattern
  @weight = nil
  parse pattern
end

Instance Method Details

#each(options = {}, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/em-fs/dir/glob.rb', line 35

def each options = {}, &block
  options = {
    depth: :inf
  }.merge options
  EM::SystemCommand.execute find_command(options) do |on|
    on.stdout.line do |line|
      block.call File::Stat.parse line
    end
  end
end

#each_entry(options = {}, &block) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/em-fs/dir/glob.rb', line 46

def each_entry options = {}, &block
  options = {
    depth: 1
  }.merge options
  each options do |stat|
    block.call ::File.basename(stat.path)
  end
end

#each_path(options = {}, &block) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/em-fs/dir/glob.rb', line 55

def each_path options = {}, &block
  options = {
    depth: :inf
  }.merge options
  each options do |stat|
    block.call stat.path
  end
end

#parse(pattern) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/em-fs/dir/glob.rb', line 12

def parse pattern
  root = []

  *path, name = pattern.split(::File::SEPARATOR)

  if name.index("*").nil?
    path << name
    name = "*"
  end

  root << path.shift while path[0] and path[0].index("*").nil?

  @name = name
  @path = path.join(::File::SEPARATOR).gsub '**', '*'
  @root = root.join(::File::SEPARATOR)

  if path.length == 0
    @weight = 1
  end

  @root = '.' if @root == ''
end