Module: SuperStack::LayerWrapper

Includes:
Comparable, MergePolicies::PolicyHandler
Included in:
Layer
Defined in:
lib/super_stack/layer_wrapper.rb

Constant Summary collapse

DEFAULT_LAYER_NAME =
'Unknown layer'

Instance Attribute Summary collapse

Attributes included from MergePolicies::PolicyHandler

#merge_policy

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



11
12
13
# File 'lib/super_stack/layer_wrapper.rb', line 11

def file_name
  @file_name
end

#priorityObject

Returns the value of attribute priority.



11
12
13
# File 'lib/super_stack/layer_wrapper.rb', line 11

def priority
  @priority
end

Class Method Details

.from_hash(hash) ⇒ Object



55
56
57
# File 'lib/super_stack/layer_wrapper.rb', line 55

def self.from_hash(hash)
  hash.extend self
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
43
# File 'lib/super_stack/layer_wrapper.rb', line 40

def <=>(other)
  # For priorities, the smallest the higher
  self.priority <=> other.priority
end

#has_file?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/super_stack/layer_wrapper.rb', line 36

def has_file?
  !@file_name.nil?
end

#inspectObject



45
46
47
48
49
# File 'lib/super_stack/layer_wrapper.rb', line 45

def inspect
  file_add_on = has_file? ? "file: '#{file_name}', " : ''
  priority_add_on = priority.nil? ? '' : "priority: #{priority}, "
  "{name: '#{name}', #{priority_add_on}#{file_add_on}#{super}}"
end

#load(file_name = self.file_name, type = :yaml) ⇒ Object



26
27
28
29
30
# File 'lib/super_stack/layer_wrapper.rb', line 26

def load(file_name=self.file_name, type = :yaml)
  raise "Cannot read file '#{file_name}'" unless File.readable? file_name
  load_from_yaml file_name if type == :yaml
  self
end

#nameObject



22
23
24
# File 'lib/super_stack/layer_wrapper.rb', line 22

def name
  @name || DEFAULT_LAYER_NAME
end

#name=(name) ⇒ Object



18
19
20
# File 'lib/super_stack/layer_wrapper.rb', line 18

def name=(name)
  @name = name.to_s
end

#reloadObject



32
33
34
# File 'lib/super_stack/layer_wrapper.rb', line 32

def reload
  self.load if has_file?
end

#to_sObject



51
52
53
# File 'lib/super_stack/layer_wrapper.rb', line 51

def to_s
  inspect
end