Class: Secrets::Secret
- Inherits:
-
Object
- Object
- Secrets::Secret
- Defined in:
- lib/secrets/secret.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Secret
constructor
A new instance of Secret.
Constructor Details
#initialize(path) ⇒ Secret
Returns a new instance of Secret.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/secrets/secret.rb', line 8 def initialize path if File.exist?(path) YAML.load_file(path).each do |(key, value)| instance_variable_set "@#{key}", OpenStruct.new(value) define_singleton_method key do instance_variable_get "@#{key}" end define_singleton_method "#{key}=" do |v| instance_variable_set "@#{key}", OpenStruct.new(v) data = YAML.load_file path data[key] = v File.open(path, 'w') { |f| YAML.dump(data, f) } end end end end |