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 = CloudConfig::Providers::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(opts = {}) ⇒ YamlFile

Create an instance of CloudConfig::Providers::YamlFile

Parameters:

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

    Yaml file options

Options Hash (opts):

  • :filename (String)

    Name of the YAML file



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

def initialize(opts = {})
  @contents = YAML.load_file(opts[: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, _opts = {}) ⇒ Object

Fetch the value of the key

Parameters:

  • key (String, Symbol)

    Key to fetch

Returns:

  • (Object)

    Value of the key



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

def get(key, _opts = {})
  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



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

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