Class | OpenWFE::YamlFileStorage |
In: |
lib/openwfe/storage/yamlfilestorage.rb
|
Parent: | Object |
Stores OpenWFEru related objects into yaml encoded files. This storage is meant to look and feel like a Hash.
basepath | [RW] |
# File lib/openwfe/storage/yamlfilestorage.rb, line 69 69: def initialize (service_name, application_context, path) 70: 71: super() 72: 73: service_init(service_name, application_context) 74: 75: @basepath = get_work_directory + path 76: @basepath += "/" unless @basepath[-1, 1] == "/" 77: 78: FileUtils.makedirs @basepath 79: end
Actually loads and returns the object for the given FlowExpressionId instance.
# File lib/openwfe/storage/yamlfilestorage.rb, line 140 140: def [] (fei) 141: 142: fei_path = compute_file_path(fei) 143: 144: if not File.exist?(fei_path) 145: 146: ldebug { "[] didn't find file at #{fei_path}" } 147: #puts "[] didn't find file at #{fei_path}" 148: 149: return nil 150: end 151: 152: load_object(fei_path) 153: end
Stores an object with its FlowExpressionId instance as its key.
# File lib/openwfe/storage/yamlfilestorage.rb, line 84 84: def []= (fei, object) 85: synchronize do 86: 87: #linfo { "[]= #{fei}" } 88: 89: fei_path = compute_file_path(fei) 90: 91: fei_parent_path = File.dirname(fei_path) 92: 93: FileUtils.makedirs(fei_parent_path) \ 94: unless File.exist?(fei_parent_path) 95: 96: File.open(fei_path, "w") do |file| 97: YAML.dump(object, file) 98: end 99: end 100: end
Removes the object (file) stored for the given FlowExpressionId instance.
# File lib/openwfe/storage/yamlfilestorage.rb, line 123 123: def delete (fei) 124: synchronize do 125: 126: fei_path = compute_file_path(fei) 127: 128: ldebug do 129: "delete()\n for #{fei.to_debug_s}\n at #{fei_path}" 130: end 131: 132: File.delete(fei_path) 133: end 134: end
Checks whether there is an object (expression, workitem) stored for the given FlowExpressionId instance.
# File lib/openwfe/storage/yamlfilestorage.rb, line 115 115: def has_key? (fei) 116: File.exist?(compute_file_path(fei)) 117: end
Returns the count of objects currently stored in this instance.
# File lib/openwfe/storage/yamlfilestorage.rb, line 158 158: def length 159: 160: count_objects() 161: end
Deletes the whole storage directory… beware…
# File lib/openwfe/storage/yamlfilestorage.rb, line 105 105: def purge 106: synchronize do 107: FileUtils.remove_dir @basepath 108: end 109: end
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.
# File lib/openwfe/storage/yamlfilestorage.rb, line 238 238: def compute_file_path (object) 239: raise NotImplementedError.new 240: end
Returns the number of ‘objects’ currently in this storage.
# File lib/openwfe/storage/yamlfilestorage.rb, line 180 180: def count_objects 181: 182: count = 0 183: 184: Find.find(@basepath) do |path| 185: 186: next unless File.exist? path 187: next if File.stat(path).directory? 188: 189: count += 1 if OpenWFE::ends_with(path, ".yaml") 190: end 191: 192: count 193: end
Passes each object to the given block
# File lib/openwfe/storage/yamlfilestorage.rb, line 218 218: def each_object (&block) 219: 220: each_object_path do |path| 221: block.call load_object(path) 222: end 223: end
Passes each object path to the given block
# File lib/openwfe/storage/yamlfilestorage.rb, line 198 198: def each_object_path (path=@basepath, &block) 199: 200: #return unless block 201: 202: synchronize do 203: Find.find(path) do |p| 204: 205: next unless File.exist?(p) 206: next if File.stat(p).directory? 207: next unless OpenWFE::ends_with(p, ".yaml") 208: 209: ldebug { "each_object_path() considering #{p}" } 210: block.call p 211: end 212: end 213: end