Class: Amigrind::Environments::Environment

Inherits:
Object
  • Object
show all
Extended by:
Core::Logging::Mixin
Defined in:
lib/amigrind/environments/environment.rb

Defined Under Namespace

Classes: AWSConfig

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



23
24
25
26
27
# File 'lib/amigrind/environments/environment.rb', line 23

def initialize
  @aws = AWSConfig.new
  @channels = []
  @properties = {}
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



21
22
23
# File 'lib/amigrind/environments/environment.rb', line 21

def properties
  @properties
end

Class Method Details

.from_yaml(name, yaml_input) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/amigrind/environments/environment.rb', line 29

def self.from_yaml(name, yaml_input)
  yaml = YAML.load(yaml_input).deep_symbolize_keys

  yaml[:amigrind] ||= {}
  yaml[:aws] ||= {}
  yaml[:properties] ||= {}

  env = Environment.new
  env.name = name.to_s.strip.downcase

  env.aws = AWSConfig.new(yaml[:aws])

  env.properties.merge!(yaml[:properties])

  env.channels = (yaml[:amigrind][:channels] || []).map do |k, v|
    [ k.to_s, Channel.new(v.merge(name: k)) ]
  end.to_h

  # TODO: use these for validations
  valid_mappings = {
    'root' => env,
    'aws' => env.aws
  }

  env
end

.load_yaml_file(path) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/amigrind/environments/environment.rb', line 56

def self.load_yaml_file(path)
  raise "'path' must be a String." unless path.is_a?(String)
  raise "'path' must be a file that exists." unless File.exist?(path)
  raise "'path' must end in .yml, .yaml, .yml.erb, or .yaml.erb." \
    unless path.end_with?('.yml', '.yaml', '.yml.erb', '.yaml.erb')

  Environment.from_yaml(File.basename(path, '.*'), Erubis::Eruby.new(File.read(path)).result)
end