Class: JackAndTheElasticBeanstalk::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jack_and_the_elastic_beanstalk/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_hash:, eb_configs:) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 6

def initialize(app_hash:, eb_configs:)
  @app_hash = app_hash
  @eb_configs = eb_configs
end

Instance Attribute Details

#app_hashObject (readonly)

Returns the value of attribute app_hash.



3
4
5
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 3

def app_hash
  @app_hash
end

#eb_configsObject (readonly)

Returns the value of attribute eb_configs.



4
5
6
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 4

def eb_configs
  @eb_configs
end

Class Method Details

.load(path:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 11

def self.load(path:)
  app_yml = path + "app.yml"
  app_hash = YAML.load_file(app_yml.to_s)

  eb_configs = path.children.each.with_object({}) do |file, acc|
    relative_path = file.relative_path_from(path)
    acc[relative_path] = file.read if file.extname == ".config"
  end

  Config.new(app_hash: app_hash, eb_configs: eb_configs)
end

Instance Method Details

#app_nameObject



23
24
25
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 23

def app_name
  app_hash.dig("application", "name")
end

#configurationsObject



35
36
37
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 35

def configurations
  app_hash["configurations"]
end

#each_configObject



51
52
53
54
55
56
57
58
59
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 51

def each_config
  if block_given?
    eb_configs.each do |path, content|
      yield path, ERB.new(content).result
    end
  else
    enum_for :each_config
  end
end

#each_process(configuration) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 61

def each_process(configuration)
  if block_given?
    processes(configuration).each do |key, hash|
      yield key, hash
    end
  else
    enum_for :each_process, configuration
  end
end

#platformObject



31
32
33
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 31

def platform
  app_hash.dig("application", "platform")
end

#process_type(configuration, process) ⇒ Object



47
48
49
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 47

def process_type(configuration, process)
  processes(configuration)[process]["type"].to_s
end

#processes(configuration) ⇒ Object



43
44
45
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 43

def processes(configuration)
  configurations[configuration].select {|_, value| value["type"] }
end

#regionObject



27
28
29
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 27

def region
  app_hash.dig("application", "region")
end

#s3_bucketObject



39
40
41
# File 'lib/jack_and_the_elastic_beanstalk/config.rb', line 39

def s3_bucket
  app_hash["s3_bucket"]
end