class Trunk::YAMLStorage
Attributes
absolute_path[R]
private_key[R]
Public Class Methods
new(absolute_path, private_key)
click to toggle source
# File lib/trunk/yaml_storage.rb, line 5 def initialize(absolute_path, private_key) @absolute_path = absolute_path @private_key = private_key end
Public Instance Methods
fetch(*args)
click to toggle source
# File lib/trunk/yaml_storage.rb, line 10 def fetch(*args) transaction do |storage| storage.fetch(*args) end end
store(*args)
click to toggle source
# File lib/trunk/yaml_storage.rb, line 16 def store(*args) transaction do |storage| storage.store(*args) end end
Private Instance Methods
serializer()
click to toggle source
# File lib/trunk/yaml_storage.rb, line 32 def serializer serializer = Trunk::Serializers::Composite.new serializer.add(Trunk::Serializers::Crypto.new(private_key)) serializer.add(Trunk::Serializers::Base64.new) serializer end
transaction() { |storage| ... }
click to toggle source
# File lib/trunk/yaml_storage.rb, line 24 def transaction hash = YAML.load(IO.read(absolute_path)) || {} storage = Storage.new(hash, serializer) yield storage ensure IO.write(absolute_path, YAML.dump(hash)) end