class Docks::Containers::Base

Public: the base container for symbols. This class should be inherited from for all other symbol containers. Its most important feature is that it normalizes synonymous tags so that any tag can be called on a container and the result will be returned as expected.

Public Class Methods

new(details = {}) click to toggle source
# File lib/docks/containers/base_container.rb, line 17
def initialize(details = {})
  if details.kind_of?(Base)
    details.delete(:symbol_type)
    details = details.to_h
  end

  details = Tags.join_synonymous_tags(details)
  @details = details
  @summary = false
end

Public Instance Methods

==(other_container) click to toggle source
# File lib/docks/containers/base_container.rb, line 31
def ==(other_container)
  self.class == other_container.class && @details == other_container.instance_variable_get(:@details)
end
[](tag) click to toggle source
# File lib/docks/containers/base_container.rb, line 40
def [](tag)
  fetch(tag, nil)
end
[]=(tag, new_value) click to toggle source
# File lib/docks/containers/base_container.rb, line 44
def []=(tag, new_value)
  tag = Tags.base_tag_name(tag)
  @details[tag] = new_value unless tag.nil?
end
delete(tag) click to toggle source
# File lib/docks/containers/base_container.rb, line 49
def delete(tag)
  @details.delete(Tags.base_tag_name(tag))
end
fetch(tag, *args) click to toggle source
# File lib/docks/containers/base_container.rb, line 53
def fetch(tag, *args)
  @details.fetch(Tags.base_tag_name(tag), *args)
end
find(descriptor) click to toggle source
# File lib/docks/containers/base_container.rb, line 87
def find(descriptor)
  descriptor = Descriptor.new(descriptor)
  matches_exactly?(descriptor) && self
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/docks/containers/base_container.rb, line 61
def method_missing(meth, *args, &block)
  stripped = meth.to_s.sub("=", "").to_sym
  has_tag = Tags.has_tag?(stripped)

  if stripped != meth && has_tag
    self[stripped] = args.first
  elsif has_tag
    fetch(meth, nil)
  else
    super(meth, *args, &block)
  end
end
respond_to?(meth) click to toggle source
Calls superclass method
# File lib/docks/containers/base_container.rb, line 74
def respond_to?(meth)
  Tags.has_tag?(meth.to_s.sub("=", "")) || super
end
summarized?() click to toggle source
# File lib/docks/containers/base_container.rb, line 78
def summarized?; @summary end
Also aliased as: summary?
summary() click to toggle source
# File lib/docks/containers/base_container.rb, line 81
def summary
  summary = self.class.new(name: self.name)
  summary.instance_variable_set(:@summary, true)
  summary
end
summary?()
Alias for: summarized?
tags() click to toggle source
# File lib/docks/containers/base_container.rb, line 57
def tags
  @details.keys.map { |tag| Tags.tag_for(tag) }
end
to_h() click to toggle source
# File lib/docks/containers/base_container.rb, line 28
def to_h; @details end
Also aliased as: to_hash
to_hash()
Alias for: to_h
update(tag) { |self| ... } click to toggle source
# File lib/docks/containers/base_container.rb, line 35
def update(tag)
  self[tag] = yield(self[tag])
  self
end

Protected Instance Methods

matches?(descriptor) click to toggle source
# File lib/docks/containers/base_container.rb, line 94
def matches?(descriptor)
  fetch(:name, nil) == descriptor.symbol
end
matches_exactly?(descriptor) click to toggle source
# File lib/docks/containers/base_container.rb, line 98
def matches_exactly?(descriptor)
  !descriptor.member? && matches?(descriptor)
end