Method: EPO::DB#delete

Defined in:
lib/epo/core/db.rb

#delete(root, resource) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/epo/core/db.rb', line 133

def delete(root, resource)
  remaining_path = File.join(root, resource.path(identifying_sym))
  # removes the resource-epo-* files
  Dir.entries(remaining_path).each do |e|
    if e.start_with?('resource-epo-')
      FileUtils.rm(File.join(remaining_path, e)) 
    end
  end

  # removes the empty directories upward
  resource.identifiers(identifying_sym).size.times do |t|
    begin
      Dir.rmdir(remaining_path)
      remaining_path = File.split(remaining_path).first
    rescue Errno::ENOTEMPTY
      break
    end
  end
end