Class: BBC::Cosmos::Tools::Config
- Inherits:
-
Object
- Object
- BBC::Cosmos::Tools::Config
- Defined in:
- lib/bbc/cosmos/tools/config.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#env ⇒ Object
Returns the value of attribute env.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #app ⇒ Object
- #cf_templates(component, stack = "main") ⇒ Object
- #components ⇒ Object
- #components_for(tags) ⇒ Object
-
#initialize(base_path, project, env = "int") ⇒ Config
constructor
A new instance of Config.
- #resources ⇒ Object
Constructor Details
#initialize(base_path, project, env = "int") ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 |
# File 'lib/bbc/cosmos/tools/config.rb', line 9 def initialize(base_path, project, env = "int") @base_path = base_path @project = project @env = env end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
7 8 9 |
# File 'lib/bbc/cosmos/tools/config.rb', line 7 def base_path @base_path end |
#env ⇒ Object
Returns the value of attribute env.
7 8 9 |
# File 'lib/bbc/cosmos/tools/config.rb', line 7 def env @env end |
#project ⇒ Object
Returns the value of attribute project.
7 8 9 |
# File 'lib/bbc/cosmos/tools/config.rb', line 7 def project @project end |
Instance Method Details
#app ⇒ Object
47 48 49 50 51 |
# File 'lib/bbc/cosmos/tools/config.rb', line 47 def app config_path = base_path.join("configs", "app.yaml") fail("Invalid application config path: #{config_path}") unless File.exist? config_path YAML.load(File.open(config_path).read)["bbc"]["cosmos"] end |
#cf_templates(component, stack = "main") ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/bbc/cosmos/tools/config.rb', line 53 def cf_templates(component, stack = "main") aws_templates = File.join(base_path, "stacks", component, stack, "/aws/**/*.rb") component_template_path = File.join(base_path, "stacks", component, stack, "template.rb") component_template = (File.exist? component_template_path) ? File.read(component_template_path) : "" Dir .glob(aws_templates) .reduce(component_template) { |template_string, file| template_string += File.read(file) } end |
#components ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bbc/cosmos/tools/config.rb', line 28 def components path = File.join(base_path, "configs", "#{project}.yaml.erb") if File.exist? path template = File.open(path).read config = resources YAML.load( ERB.new(template).result(binding) )["components"] else fail("'#{project}' isn't valid project") end end |
#components_for(tags) ⇒ Object
41 42 43 44 45 |
# File 'lib/bbc/cosmos/tools/config.rb', line 41 def components_for() resources["cloudformation"]["components"].select do |_component_id, data| data["tags"].any? { |tag| .nil? ? true : .include?(tag) } if data["tags"] end end |
#resources ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bbc/cosmos/tools/config.rb', line 15 def resources if File.directory? File.join(base_path, "resources", env) path = File.join(base_path, "resources", env, "#{project}.yaml") if File.exist? path YAML.load(File.open(path).read) else fail("Invalid project, please set the $BBC_COSMOS_TOOLS_PROJECT environment variable or use the --project parameter") end else fail("#{env} is an invalid environment") end end |