Class: OpenWFE::YamlFileStorage
- Inherits:
-
Object
- Object
- OpenWFE::YamlFileStorage
- Includes:
- MonitorMixin, ServiceMixin
- Defined in:
- lib/openwfe/storage/yamlfilestorage.rb
Overview
Stores OpenWFEru related objects into yaml encoded files. This storage is meant to look and feel like a Hash.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#basepath ⇒ Object
Returns the value of attribute basepath.
Attributes included from ServiceMixin
Attributes included from Contextual
Instance Method Summary collapse
-
#[](fei) ⇒ Object
Actually loads and returns the object for the given FlowExpressionId instance.
-
#[]=(fei, object) ⇒ Object
Stores an object with its FlowExpressionId instance as its key.
-
#delete(fei) ⇒ Object
Removes the object (file) stored for the given FlowExpressionId instance.
-
#has_key?(fei) ⇒ Boolean
Checks whether there is an object (expression, workitem) stored for the given FlowExpressionId instance.
-
#initialize(service_name, application_context, path) ⇒ YamlFileStorage
constructor
A new instance of YamlFileStorage.
-
#length ⇒ Object
(also: #size)
Returns the count of objects currently stored in this instance.
-
#purge ⇒ Object
Deletes the whole storage directory…
Methods included from ServiceMixin
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Constructor Details
#initialize(service_name, application_context, path) ⇒ YamlFileStorage
Returns a new instance of YamlFileStorage.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 69 def initialize (service_name, application_context, path) super() service_init(service_name, application_context) @basepath = get_work_directory + path @basepath += "/" unless @basepath[-1, 1] == "/" FileUtils.makedirs @basepath end |
Instance Attribute Details
#basepath ⇒ Object
Returns the value of attribute basepath.
67 68 69 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 67 def basepath @basepath end |
Instance Method Details
#[](fei) ⇒ Object
Actually loads and returns the object for the given FlowExpressionId instance.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 140 def [] (fei) fei_path = compute_file_path(fei) if not File.exist?(fei_path) ldebug { "[] didn't find file at #{fei_path}" } #puts "[] didn't find file at #{fei_path}" return nil end load_object(fei_path) end |
#[]=(fei, object) ⇒ Object
Stores an object with its FlowExpressionId instance as its key.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 84 def []= (fei, object) synchronize do #linfo { "[]= #{fei}" } fei_path = compute_file_path(fei) fei_parent_path = File.dirname(fei_path) FileUtils.makedirs(fei_parent_path) \ unless File.exist?(fei_parent_path) File.open(fei_path, "w") do |file| YAML.dump(object, file) end end end |
#delete(fei) ⇒ Object
Removes the object (file) stored for the given FlowExpressionId instance.
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 123 def delete (fei) synchronize do fei_path = compute_file_path(fei) ldebug do "delete()\n for #{fei.to_debug_s}\n at #{fei_path}" end File.delete(fei_path) end end |
#has_key?(fei) ⇒ Boolean
Checks whether there is an object (expression, workitem) stored for the given FlowExpressionId instance.
115 116 117 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 115 def has_key? (fei) File.exist?(compute_file_path(fei)) end |
#length ⇒ Object Also known as: size
Returns the count of objects currently stored in this instance.
158 159 160 161 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 158 def length count_objects() end |
#purge ⇒ Object
Deletes the whole storage directory… beware…
105 106 107 108 109 |
# File 'lib/openwfe/storage/yamlfilestorage.rb', line 105 def purge synchronize do FileUtils.remove_dir @basepath end end |