Class: EventMachine::Dir::Glob
- Inherits:
-
Object
- Object
- EventMachine::Dir::Glob
- 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
- #each(options = {}, &block) ⇒ Object
- #each_entry(options = {}, &block) ⇒ Object
- #each_path(options = {}, &block) ⇒ Object
-
#initialize(pattern) ⇒ Glob
constructor
A new instance of Glob.
- #parse(pattern) ⇒ Object
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 = {}, &block = { depth: :inf }.merge EM::SystemCommand.execute find_command() 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 = {}, &block = { depth: 1 }.merge each 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 = {}, &block = { depth: :inf }.merge each 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 |