lib/openwfe/storage/yamlfilestorage.rb in openwferu-0.9.6 vs lib/openwfe/storage/yamlfilestorage.rb in openwferu-0.9.7
- old
+ new
@@ -140,57 +140,71 @@
#
def [] (fei)
fei_path = compute_file_path(fei)
- return nil if not File.exist?(fei_path)
+ if not File.exist?(fei_path)
+ ldebug { "[] didn't find file at #{fei_path}" }
+ return nil
+ end
load_object(fei_path)
end
#
# Returns the count of objects currently stored in this instance.
#
def length
- #return count_objects(0, @basepath)
+
count_objects()
end
alias :size :length
protected
def load_object (path)
- #data = IO.read(path)
- #object = YAML.load(data)
object = YAML.load_file(path)
object.application_context = @application_context \
if object.respond_to? :application_context=
object
end
+ #
+ # Returns the number of 'objects' currently in this storage.
+ #
def count_objects
+
count = 0
+
Find.find(@basepath) do |path|
+
+ next unless File.exist? path
next if File.stat(path).directory?
+
count += 1 if OpenWFE::ends_with(path, ".yaml")
end
return count
end
#
# Passes each object path to the given block
#
def each_object_path (&block)
+
return unless block
+
synchronize do
Find.find(@basepath) do |path|
+
+ next unless File.exist? path
next if File.stat(path).directory?
next unless OpenWFE::ends_with(path, ".yaml")
+
ldebug { "each_object_path() considering #{path}" }
block.call path
end
end
end
@@ -210,9 +224,14 @@
#
alias :each_value :each_object
protected
+ #
+ # Each object is meant to have a unique file path,
+ # this method wraps the determination of that path. It has to
+ # be provided by extending classes.
+ #
def compute_file_path (object)
raise NotImplementedError.new
end
end