Class: Ensconce::YamlFileAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/ensconce/adapters/yaml_file_adapter.rb

Instance Attribute Summary

Attributes inherited from Adapter

#params, #settings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

config, for, #initialize, options, #options, options=

Constructor Details

This class inherits a constructor from Ensconce::Adapter

Class Method Details

.allObject



4
5
6
# File 'lib/ensconce/adapters/yaml_file_adapter.rb', line 4

def self.all
  YAML.load_file options[:file]
end

Instance Method Details

#getObject



8
9
10
11
12
# File 'lib/ensconce/adapters/yaml_file_adapter.rb', line 8

def get
  raise "No file defined" unless options[:file]
  data = YAML.load_file options[:file]
  data[settings.id]
end

#push(data) ⇒ Object



14
15
16
17
# File 'lib/ensconce/adapters/yaml_file_adapter.rb', line 14

def push(data)
  result = Mangle.deep_merge self.class.all, {settings.id => data}
  File.open(options[:file], 'w+') {|f| f.write(result.to_yaml) }
end