Module: Aws::Session::Credentials::FileProvider::YamlFileProvider
- Defined in:
- lib/aws/session/credentials/file_provider/yaml_file_provider.rb
Overview
Mixin to store configuration in a YAML file
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #read ⇒ Hash private
- #write(hash) ⇒ Object private
Instance Method Details
#[](key) ⇒ Object
7 8 9 |
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 7 def [](key) read[key] end |
#[]=(key, value) ⇒ Object
11 12 13 14 15 |
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 11 def []=(key, value) hash = read.dup hash[key] = value write(hash) end |
#read ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 |
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 19 def read return {} unless File.exist?(path) YAML.load(File.read(path)).deep_symbolize_keys end |
#write(hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 |
# File 'lib/aws/session/credentials/file_provider/yaml_file_provider.rb', line 26 def write(hash) hsh = hash.deep_stringify_keys FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path) File.open(path, 'w', 0600) { |file| file.write(YAML.dump(hsh)) } end |