module SuperStack::LayerWrapper

Constants

DEFAULT_LAYER_NAME

Attributes

disabled[R]
disabled?[R]
file_name[R]
manager[R]
priority[R]
source_auto_reload[W]

Public Class Methods

from_hash(hash) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 74
def self.from_hash(hash)
  class << hash; include SuperStack::LayerWrapper; end
  if SuperStack.compatibility_mode
    class << hash; include SuperStack::Compatibility::LayerWrapper; end
  end
  hash
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 58
def <=>(other)
  # For priorities, the smallest the higher
  return nil unless other.respond_to? :priority
  priority <=> other.priority
end
disable_source_auto_reload() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 32
def disable_source_auto_reload
  self.source_auto_reload = false
end
enable_source_auto_reload() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 28
def enable_source_auto_reload
  self.source_auto_reload = true
end
has_file?() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 54
def has_file?
  !@file_name.nil?
end
inspect() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 64
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) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 44
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
name() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 40
def name
  @name || DEFAULT_LAYER_NAME
end
name=(name) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 36
def name=(name)
  @name = name.to_s
end
priority=(priority) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 15
def priority=(priority)
  raise 'invalid priority' unless priority.is_a? Numeric
  @priority = priority
end
reload() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 50
def reload
  self.load if has_file?
end
source_auto_reload() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 20
def source_auto_reload
  @source_auto_reload || false
end
source_auto_reload?() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 24
def source_auto_reload?
  self.source_auto_reload
end
to_hash() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 82
def to_hash
  # Trick to return a bare hash
  {}.merge self
end
to_s() click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 70
def to_s
  inspect
end

Private Instance Methods

load_from_yaml(file_name) click to toggle source
# File lib/super_stack/layer_wrapper.rb, line 90
def load_from_yaml(file_name)
  raw_content = File.read file_name
  res = YAML.load raw_content
  if res
    self.replace Hash[res.map { |k, v| [k, v] }]
  else
    raise "Invalid file content for '#{file_name}'" unless raw_content.empty?
    clear
  end
  @file_name = file_name
end