Module: FSDB::DirectoryIterators

Included in:
Database
Defined in:
lib/fsdb/util.rb

Instance Method Summary collapse

Instance Method Details

#browse_dir(path = "/") ⇒ Object

path should be either a directory or a file that contains an object whose each method yields file names.



74
75
76
77
78
79
80
# File 'lib/fsdb/util.rb', line 74

def browse_dir path = "/"
  browse path do |entries|
    entries.each do |entry|
      yield File.join(path, entry)
    end
  end
end

#browse_each_child(path = "/") ⇒ Object



90
91
92
93
94
95
96
# File 'lib/fsdb/util.rb', line 90

def browse_each_child path = "/"
  browse_dir path do |child_path|
    browse child_path do |child_object|
      yield child_path, child_object
    end
  end
end

#delete_each_child(path = "/") ⇒ Object



114
115
116
117
118
119
120
# File 'lib/fsdb/util.rb', line 114

def delete_each_child path = "/"
  edit_dir path do |child_path|           # note edit_dir
    delete child_path do |child_object|
      yield child_path, child_object
    end
  end
end

#edit_dir(path = "/") ⇒ Object



82
83
84
85
86
87
88
# File 'lib/fsdb/util.rb', line 82

def edit_dir path = "/"
  edit path do |entries|
    entries.each do |entry|
      yield File.join(path, entry)
    end
  end
end

#edit_each_child(path = "/") ⇒ Object



98
99
100
101
102
103
104
# File 'lib/fsdb/util.rb', line 98

def edit_each_child path = "/"
  browse_dir path do |child_path|
    edit child_path do |child_object|
      yield child_path, child_object
    end
  end
end

#replace_each_child(path = "/") ⇒ Object



106
107
108
109
110
111
112
# File 'lib/fsdb/util.rb', line 106

def replace_each_child path = "/"
  browse_dir path do |child_path|
    replace child_path do |child_object|
      yield child_path, child_object
    end
  end
end