Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/project.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Instance Method Summary collapse
- #account_env_map ⇒ Object
- #env_region_map ⇒ Object
- #environments ⇒ Object
- #get_lambdas ⇒ Object
-
#initialize(project_path) ⇒ Project
constructor
A new instance of Project.
- #update_by_artifact(lambda_env_map, artifact, version, sha1 = nil) ⇒ Object
- #write_new_files(lambda_env_map) ⇒ Object
Constructor Details
#initialize(project_path) ⇒ Project
Returns a new instance of Project.
5 6 7 8 |
# File 'lib/project.rb', line 5 def initialize(project_path) @config = YAML.load_file("#{project_path}/config/config.yaml") @project_path = project_path end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
2 3 4 |
# File 'lib/project.rb', line 2 def config @config end |
#project_path ⇒ Object
Returns the value of attribute project_path.
3 4 5 |
# File 'lib/project.rb', line 3 def project_path @project_path end |
Instance Method Details
#account_env_map ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/project.rb', line 22 def account_env_map hash = {} config['environments'].each do |env, properties| if hash[properties['account']].nil? hash[properties['account']] = [] hash[properties['account']] << env else hash[properties['account']] << env end end hash end |
#env_region_map ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/project.rb', line 35 def env_region_map hash = {} config['environments'].each do |env, properties| if hash[env].nil? hash[env] = properties['region'] else raise("An environment cannot map to more than one region ENV: #{env} Region: #{properties['region']}") end end hash end |
#environments ⇒ Object
10 11 12 |
# File 'lib/project.rb', line 10 def environments config['environments'] end |
#get_lambdas ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/project.rb', line 14 def get_lambdas lambdas = {} environments.keys.each do |env| lambdas[env] = YAML.load_file("#{project_path}/environments/#{env}.yaml") if File.exist?("#{project_path}/environments/#{env}.yaml") end lambdas end |
#update_by_artifact(lambda_env_map, artifact, version, sha1 = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/project.rb', line 55 def update_by_artifact(lambda_env_map, artifact, version, sha1=nil) #iterate through all lambdas and update the ones with version changes lambda_env_map.each do |env, lambda| pp env pp lambda lambda.each do |lambda_name, properties| if properties['artifact_name'] == artifact properties['version'] = version properties['sha1'] = sha1 unless sha1.nil? end end end lambda_env_map end |
#write_new_files(lambda_env_map) ⇒ Object
49 50 51 52 53 |
# File 'lib/project.rb', line 49 def write_new_files(lambda_env_map) lambda_env_map.each do |env, contents| File.write("#{project_path}/environments/#{env}.yaml", contents.to_yaml) end end |