Class: Cloudspin::Stack::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudspin/stack/definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path:, stack_name:, stack_version: '0', from_remote: false) ⇒ Definition

Returns a new instance of Definition.



11
12
13
14
15
16
# File 'lib/cloudspin/stack/definition.rb', line 11

def initialize(source_path:, stack_name:, stack_version: '0', from_remote: false)
  @source_path = source_path
  @name = stack_name
  @version = stack_version
  @from_remote = from_remote
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cloudspin/stack/definition.rb', line 7

def name
  @name
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



9
10
11
# File 'lib/cloudspin/stack/definition.rb', line 9

def source_path
  @source_path
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/cloudspin/stack/definition.rb', line 8

def version
  @version
end

Class Method Details

.from_file(specfile, from_remote: false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cloudspin/stack/definition.rb', line 18

def self.from_file(specfile, from_remote: false)
  raise NoStackDefinitionConfigurationFileError, "Did not find file '#{specfile}'" unless File.exists?(specfile)
  source_path = File.dirname(specfile)
  spec_hash = YAML.load_file(specfile)
  self.new(
    source_path: source_path,
    stack_name: spec_hash.dig('stack', 'name'),
    stack_version: spec_hash.dig('stack', 'version'),
    from_remote: from_remote
  )
end

.from_location(definition_location = nil, definition_cache_folder: '.cloudspin/definitions', stack_configuration: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cloudspin/stack/definition.rb', line 30

def self.from_location(definition_location = nil,
    definition_cache_folder: '.cloudspin/definitions',
    stack_configuration: nil
)
  resolved_definition_location = if ! definition_location.nil?
    # puts "DEBUG: definition_location has been explicitly set to #{definition_location}"
    definition_location
  elsif ! stack_configuration.nil? && stack_configuration['definition_location']
    # puts "DEBUG: definition_location comes from the stack configuration (#{stack_configuration})"
    stack_configuration['definition_location']
  else
    './src'
  end

  # puts "DEBUG: get definition from location #{resolved_definition_location}"
  if RemoteDefinition.is_remote?(resolved_definition_location)
    # puts "DEBUG: Downloading remote stack definition"
    local_definition_folder = RemoteDefinition.new(resolved_definition_location).fetch(definition_cache_folder)
    from_file("#{local_definition_folder}/stack-definition.yaml", from_remote: true)
  else
    # puts "DEBUG: Using local stack definition source: #{resolved_definition_location}/stack-definition.yaml"
    from_file("#{resolved_definition_location}/stack-definition.yaml")
  end
end

Instance Method Details

#is_from_remote?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/cloudspin/stack/definition.rb', line 55

def is_from_remote?
  @from_remote
end