Class: ElasticBeans::ApplicationVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_beans/application_version.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_label, application:, elastic_beanstalk:) ⇒ ApplicationVersion

Create a representation of an existing application version in Elastic Beanstalk. Details will be fetched from the Elastic Beanstalk API.



15
16
17
18
19
# File 'lib/elastic_beans/application_version.rb', line 15

def initialize(version_label, application:, elastic_beanstalk:)
  @version_label = version_label
  @application = application
  @elastic_beanstalk = elastic_beanstalk
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



10
11
12
# File 'lib/elastic_beans/application_version.rb', line 10

def application
  @application
end

#version_description=(value) ⇒ Object

Sets the attribute version_description

Parameters:

  • value

    the value to set the attribute version_description to.



11
12
13
# File 'lib/elastic_beans/application_version.rb', line 11

def version_description=(value)
  @version_description = value
end

#version_labelObject (readonly)

Returns the value of attribute version_label.



10
11
12
# File 'lib/elastic_beans/application_version.rb', line 10

def version_label
  @version_label
end

Class Method Details

.create(working_directory:, application:, elastic_beanstalk:, s3:) ⇒ Object

Create a new Elastic Beanstalk application version from the HEAD git commit of the given working_directory. Returns immediately if the application version already exists in Elastic Beanstalk.

Injects helper code from this library to enable the functionality described in the README.

Raises an error if the application version cannot be processed by Elastic Beanstalk.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/elastic_beans/application_version.rb', line 36

def create(working_directory:, application:, elastic_beanstalk:, s3:)
  version_label = fetch_version_label(working_directory)
  if application.versions.any? { |version| version.version_label == version_label }
    return new(version_label, application: application, elastic_beanstalk: elastic_beanstalk)
  end

  archive_path = File.join(working_directory, ".elasticbeanstalk", "#{version_label}.zip")
  create_archive(working_directory: working_directory, sha: version_label, path: archive_path)
  create_application_version(
    path: archive_path,
    version_label: version_label,
    application: application,
    elastic_beanstalk: elastic_beanstalk,
    s3: s3,
  )
  new(version_label, application: application, elastic_beanstalk: elastic_beanstalk)
end

.new_from_existing(version_description, application:, elastic_beanstalk:) ⇒ Object

Create a representation of an existing application version in Elastic Beanstalk. version_description should be the Aws::ElasticBeanstalk::Types::ApplicationVersionDescription from the AWS API.



23
24
25
26
27
# File 'lib/elastic_beans/application_version.rb', line 23

def self.new_from_existing(version_description, application:, elastic_beanstalk:)
  version = new(version_description.version_label, application: application, elastic_beanstalk: elastic_beanstalk)
  version.version_description = version_description
  version
end

Instance Method Details

#==(other) ⇒ Object



194
195
196
197
# File 'lib/elastic_beans/application_version.rb', line 194

def ==(other)
  version_label == other.version_label &&
    application.name == other.application.name
end

#date_updatedObject



190
191
192
# File 'lib/elastic_beans/application_version.rb', line 190

def date_updated
  version_description.date_updated
end

#deleteObject



179
180
181
182
183
184
185
186
187
188
# File 'lib/elastic_beans/application_version.rb', line 179

def delete
  elastic_beanstalk.delete_application_version(
    application_name: application.name,
    version_label: version_label,
    delete_source_bundle: true,
  )
rescue ::Aws::ElasticBeanstalk::Errors::Throttling
  sleep 5
  retry
end