Class: Biosphere::Suite
- Inherits:
-
Object
- Object
- Biosphere::Suite
- Defined in:
- lib/biosphere/suite.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#biosphere_settings ⇒ Object
readonly
Returns the value of attribute biosphere_settings.
-
#deployments ⇒ Object
readonly
Returns the value of attribute deployments.
-
#files ⇒ Object
Returns the value of attribute files.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #call_action(name, context) ⇒ Object
- #evaluate_resources ⇒ Object
-
#initialize(state) ⇒ Suite
constructor
A new instance of Suite.
- #load_all(directory) ⇒ Object
- #node ⇒ Object
- #register(deployment) ⇒ Object
- #write_json_to(destination_dir) ⇒ Object
Constructor Details
#initialize(state) ⇒ Suite
Returns a new instance of Suite.
12 13 14 15 16 17 18 19 20 |
# File 'lib/biosphere/suite.rb', line 12 def initialize(state) @files = {} @actions = {} @state = state @deployments = {} @biosphere_settings = {} @biosphere_path = "" end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
9 10 11 |
# File 'lib/biosphere/suite.rb', line 9 def actions @actions end |
#biosphere_settings ⇒ Object (readonly)
Returns the value of attribute biosphere_settings.
10 11 12 |
# File 'lib/biosphere/suite.rb', line 10 def biosphere_settings @biosphere_settings end |
#deployments ⇒ Object (readonly)
Returns the value of attribute deployments.
10 11 12 |
# File 'lib/biosphere/suite.rb', line 10 def deployments @deployments end |
#files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/biosphere/suite.rb', line 8 def files @files end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
10 11 12 |
# File 'lib/biosphere/suite.rb', line 10 def state @state end |
Instance Method Details
#call_action(name, context) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/biosphere/suite.rb', line 76 def call_action(name, context) found = false @files.each do |file_name, proxy| if proxy.actions[name] found = true proxy.call_action(name, context) end end return found end |
#evaluate_resources ⇒ Object
41 42 43 44 45 |
# File 'lib/biosphere/suite.rb', line 41 def evaluate_resources() @deployments.each do |name, deployment| deployment.evaluate_resources() end end |
#load_all(directory) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/biosphere/suite.rb', line 51 def load_all(directory) @directory = directory files = Dir::glob("#{directory}/*.rb") for file in files proxy = Biosphere::TerraformProxy.new(file, self) @files[file[directory.length+1..-1]] = proxy end @files.each do |file_name, proxy| proxy.load_from_file() proxy.actions.each do |key, value| if @actions[key] raise "Action '#{key}' already defined at #{value[:location]}" end @actions[key] = value end end return @files.length end |
#node ⇒ Object
47 48 49 |
# File 'lib/biosphere/suite.rb', line 47 def node @state.node end |
#register(deployment) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/biosphere/suite.rb', line 22 def register(deployment) if @deployments[deployment.name] raise RuntimeException.new("Deployment #{deployment.name} already registered") end @deployments[deployment.name] = deployment if !@state.node[:deployments] @state.node[:deployments] = Node::Attribute.new end @state.node[:deployments][deployment.name] = Node::Attribute.new deployment.node = Node.new(@state.node[:deployments][deployment.name]) #@state.node.deep_set(:deployments, deployment.name, deployment.node.data) deployment.state = @state if deployment._settings[:biosphere] @biosphere_settings.deep_merge!(deployment._settings[:biosphere]) end end |
#write_json_to(destination_dir) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/biosphere/suite.rb', line 88 def write_json_to(destination_dir) if !File.directory?(destination_dir) Dir.mkdir(destination_dir) end @deployments.each do |name, deployment| dir = destination_dir + "/" + deployment.name if !File.directory?(dir) Dir.mkdir(dir) end json_name = deployment.name + ".json.tf" str = deployment.to_json(true) + "\n" destination_name = dir + "/" + json_name File.write(destination_name, str) yield deployment.name, destination_name, str, deployment if block_given? end end |