Class: Vault::Storage::YamlStore
- Inherits:
-
Object
- Object
- Vault::Storage::YamlStore
- Includes:
- Enumerable
- Defined in:
- lib/vault/storage/yaml_store.rb
Instance Method Summary collapse
- #filter(query) ⇒ Object
- #flush ⇒ Object
-
#initialize(file = nil) ⇒ YamlStore
constructor
A new instance of YamlStore.
- #initialize_copy ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ YamlStore
Returns a new instance of YamlStore.
11 12 13 14 |
# File 'lib/vault/storage/yaml_store.rb', line 11 def initialize(file=nil) @file = file at_exit { flush if @file.present? } end |
Instance Method Details
#filter(query) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vault/storage/yaml_store.rb', line 20 def filter(query) return filtered_copy(@doc) if query.blank? results = doc.inject(ActiveSupport::OrderedHash.new) do |result, (key, properties)| result[key] = properties if properties.merge(query) == properties result end filtered_copy(results) end |
#flush ⇒ Object
31 32 33 |
# File 'lib/vault/storage/yaml_store.rb', line 31 def flush File.open(@file, "w+") {|f| YAML.dump(@doc, f) } end |
#initialize_copy ⇒ Object
16 17 18 |
# File 'lib/vault/storage/yaml_store.rb', line 16 def initialize_copy(*) @file = nil end |