Class: Vmit::FilesystemRegistry
- Defined in:
- lib/vmit/registry.rb
Overview
Takes configuration options from a filesystem tree where the files are the keys and the content the values
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(base_path) ⇒ FilesystemRegistry
constructor
A new instance of FilesystemRegistry.
- #keys ⇒ Object
Constructor Details
#initialize(base_path) ⇒ FilesystemRegistry
Returns a new instance of FilesystemRegistry.
171 172 173 |
# File 'lib/vmit/registry.rb', line 171 def initialize(base_path) @base_path = base_path end |
Instance Method Details
#[](key) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/vmit/registry.rb', line 175 def [](key) begin path = File.join(@base_path, key.to_s) unless File.directory?(path) File.read(path) else return FilesystemRegistry.new(File.join(@base_path, path)) end rescue Errno::ENOENT nil end end |
#[]=(key, val) ⇒ Object
188 189 190 |
# File 'lib/vmit/registry.rb', line 188 def []=(key, val) File.write(File.join(@base_path, key.to_s), val) end |
#each(&block) ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/vmit/registry.rb', line 192 def each(&block) Enumerator.new do |enum| Dir.entries(@base_path).reject do |elem| ['.', '..'].include?(elem) end.each do |key| enum.yield key.to_sym, self[key] end end end |
#keys ⇒ Object
202 203 204 |
# File 'lib/vmit/registry.rb', line 202 def keys each.to_a.map(&:first) end |