Class: CloudConfig::Providers::YamlFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud-config/providers/yaml_file.rb

Overview

A class for fetching configuration from the AWS Parameter Store

Examples:

provider = YamlFile.new # Assuming AWS credentials are already configured
provider.set(:example_key, :example_value)
provider.get(:example_key) #=> 'example_value'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ YamlFile

Create an instance of CloudConfig::Providers::YamlFile

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :filename (Hash)

    Name of the YAML file



19
20
21
# File 'lib/cloud-config/providers/yaml_file.rb', line 19

def initialize(params = {})
  @contents = YAML.load_file(params[:filename]) || {}
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



14
15
16
# File 'lib/cloud-config/providers/yaml_file.rb', line 14

def contents
  @contents
end

#Contents of the Yaml file(oftheYamlfile) ⇒ Hash (readonly)

Returns:

  • (Hash)


14
# File 'lib/cloud-config/providers/yaml_file.rb', line 14

attr_reader :contents

Instance Method Details

#get(key) ⇒ Object

Fetch the value of the key

Parameters:

  • key (String, Symbol)

    Key to fetch

Returns:

  • (Object)

    Value of the key



28
29
30
# File 'lib/cloud-config/providers/yaml_file.rb', line 28

def get(key)
  contents[key]
end

#set(key, value) ⇒ Object

Set the value of the key

Parameters:

  • key (String, Symbol)

    Key to set

  • value (Object)

    Value of the key



36
37
38
# File 'lib/cloud-config/providers/yaml_file.rb', line 36

def set(key, value)
  @contents[key] = value
end