class Andromeda::Impl::ProtoPlan

Attributes

guide[R]
id[R]

Public Class Methods

name_spot(*names) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 13
def self.name_spot(*names) ; name_attr_set '@spot_names', *names end
new(config = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 45
def initialize(config = {})
  @id      = Id.new
  set_from_config init_from_config, config
  @tags  ||= {}
  self.guide=(init_guide) unless @guide
end
signal_names(inherit = true) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 39
def self.signal_names(inherit = true) ; get_attr_set '@signal_names', inherit end
signal_spot(*names) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 40
def self.signal_spot(*names) ; name_attr_set '@signal_names', *names end
spot_attr(*names) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 23
def self.spot_attr(*names)
  name_spot *names
  name_attr_set '@spot_attr_names', *names
  attr_writer *names
  names.each do |name|
    define_method :"#{name}" do ||
      intern (instance_variable_get("@#{name}"))
    end
    define_method :"#{name}=" do |val|
      if val
        then instance_variable_set "@#{name}", intern(val.entry)
        else instance_variable_set "@#{name}", nil end
    end
  end
end
spot_attr_names(inherit = true) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 11
def self.spot_attr_names(inherit = true) ; get_attr_set '@spot_attr_names', inherit end
spot_meth(name, opts = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 15
def self.spot_meth(name, opts = {})
  name_spot name
  name_attr_set '@spot_meth_names', name
  define_method :"#{name}" do ||
    mk_spot name, opts = {}
  end
end
spot_meth_names(inherit = true) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 12
def self.spot_meth_names(inherit = true) ; get_attr_set '@spot_meth_names', inherit end
spot_names(inherit = true) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 10
def self.spot_names(inherit = true) ; get_attr_set '@spot_names', inherit end

Public Instance Methods

>>(spot) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 153
def >>(spot)
  @emit = spot.entry
  d     = spot.dest 
  if d then d else spot end
end
current_name() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 151
def current_name ;  tags[:name] end
current_scope() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 150
def current_scope ;  tags[:scope] end
data_key(name, data) click to toggle source

Override to extract the data key from mapped, incoming data, defaults to name

# File lib/andromeda/impl/proto_plan.rb, line 77
def data_key(name, data) ; name end
data_tag(name, key, val, tags_in) click to toggle source

Override to compute additional tags

# File lib/andromeda/impl/proto_plan.rb, line 89
def data_tag(name, key, val, tags_in) ; { name: name } end
data_val(name, data) click to toggle source

Override to extract the data value from mapped, incoming data, defaults to data

# File lib/andromeda/impl/proto_plan.rb, line 86
def data_val(name, data) ; data end
dest() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 160
def dest ; emit end
entry() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 159
def entry ; enter end
guide=(new_guide) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 63
def guide=(new_guide)
  @guide = if new_guide.is_a?(Class)
    if new_guide.include?(Singleton) 
      then new_guide.instance
      else new_guide.new end
  else
    new_guide
  end
end
init_guide() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 57
def init_guide ; Guides.default end
initialize_copy(other) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 52
def initialize_copy(other)
  @tags    = @tags.identical_copy
  @tags  ||= {}
end
key_label(name, key) click to toggle source

Override to determine the target track label from the key, defaults to key

# File lib/andromeda/impl/proto_plan.rb, line 83
def key_label(name, key) ; key end
key_spot(name, key) click to toggle source

Override to determine the target spot name from the key, defaults to name

# File lib/andromeda/impl/proto_plan.rb, line 80
def key_spot(name, key) ; name end
map_data(name, data) click to toggle source

Override to map all incoming data, default to data

# File lib/andromeda/impl/proto_plan.rb, line 74
def map_data(name, data) ; data end
mute() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 161
def mute ; @emit = nil end
post_data(spot_, track_in, data, tags_in = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 94
def post_data(spot_, track_in, data, tags_in = {})
  raise ArgumentError, "#{spot_} is not a Spot" unless spot_.is_a?(Spot)
  raise ArgumentError, "#{spot_} is not a Spot of this Plan" unless spot_.plan == self

  name     = spot_.name
  details  = { name: name, data: data, tags_in: tags_in, spot: spot_ }
  begin
    data   = map_data name, data
    key    = data_key name, data
    name   = key_spot name, key

    guide_ = guide
    label  = key_label name, key
    details[:label] = label
    track_ = guide_.track spot_, label, track_in
    details[:track] = track_

    value  = data_val name, data
    details[:val] = value
    tags_in.update data_tag name, key, value, tags_in
    tags_in.update guide_.provision track_, label, tags_in

    pack_  = guide_.pack self, track_, track_.equal?(track_in)
    details[:pack] = pack_
    meth   = pack_.method :"on_#{name}"

    if selects? name, key, value, tags_in
      pack_.transport_data name, track_, meth, key, value, tags_in
    end
  rescue Exception => e
    raise SendError, InfoMsg.str('send_data failed', details, e), e.backtrace
  end
end
post_to(track, data, tags_in = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 164
def post_to(track, data, tags_in = {}) ; start.post_to track, data, tags_in end
public_spot(name) click to toggle source

@return [Spot, nil] public spot with name name if any, nil otherwise

# File lib/andromeda/impl/proto_plan.rb, line 130
def public_spot(name)
  raise ArgumentError, "#{name} is not a Symbol" unless name.is_a? Symbol
  raise ArgumentError, "#{name} is not a known spot name" unless spot_name? name

  if respond_to?(name)
    then intern public_send(name)
    else nil
  end
end
selects?(name, key, val, tags_in) click to toggle source

Override to filter the data events that should be processed, defaults to true

# File lib/andromeda/impl/proto_plan.rb, line 92
def selects?(name, key, val, tags_in) ; true end
signal_name?(name) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 143
def signal_name?(name) ; signal_names.include? name end
signal_names() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 148
def signal_names ; self.class.signal_names end
spot_attr_name?(name) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 141
def spot_attr_name?(name) ; spot_attr_names.include? name end
spot_attr_names() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 146
def spot_attr_names ; self.class.spot_attr_names end
spot_meth_name?(name) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 142
def spot_meth_name?(name) ; spot_meth_names.include? name end
spot_meth_names() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 147
def spot_meth_names ; self.class.spot_meth_names end
spot_name?(name) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 140
def spot_name?(name) ; spot_names.include? name end
spot_names() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 145
def spot_names ; self.class.spot_names end
tags() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 59
def tags ; @tags end
to_short_s() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 60
def to_short_s ; " id=#{id.to_short_s}t" end
via(spot_name) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 162
def via(spot_name) ; entry.via(spot_name) end

Protected Instance Methods

call_local(spot_name, key, val) click to toggle source

Call local method spot with name spot_name with key and val without any preprocessing

Requires that spot_name resolves to a spot of this plan

# File lib/andromeda/impl/proto_plan.rb, line 194
def call_local(spot_name, key, val)
  spot_ = spot spot_name
  raise ArgumentError, "#{name} could not be resolved to a Spot" unless spot_
  raise ArgumenError, "Cannot call_local for other Plans" unless spot_.plan == self
  send :"on_#{spot_name}", key, val
end
exit() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 170
def exit ; emit end
init_from_config() click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 172
def init_from_config ; [:readers, :writers] end
intern(spot) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 217
def intern(spot)
  return nil unless spot
  raise ArgumentError unless spot.is_a? Spot
  spot.intern(self)
end
mk_spot(name, opts = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 213
def mk_spot(name, opts = {})
  Spot.new self, name, self, opts[:dest]
end
set_from_config(what, config = {}) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 174
def set_from_config(what, config = {})
  init_readers = what.include? :readers
  init_writers = what.include? :writers
  config.each_pair do |k, v|
    k = k.to_sym rescue nil
    if init_writers
      writer = :"#{k}=" rescue nil
      if writer && self.respond_to?(writer)
        then self.send writer, v
        else instance_variable_set "@#{k}", v if init_readers && self.respond_to?(k) end
    else
      instance_variable_set "@#{k}", v if init_readers && self.respond_to?(k)
    end
  end
end
signal_error(e) click to toggle source
# File lib/andromeda/impl/proto_plan.rb, line 223
def signal_error(e) ; raise e end
spot(name) click to toggle source

@return [Spot, nil] public spot with name name if any, nil otherwise

# File lib/andromeda/impl/proto_plan.rb, line 203
def spot(name)
  raise ArgumentError, "#{name} is not a Symbol" unless name.is_a? Symbol
  raise ArgumentError, "#{name} is not a known spot name" unless spot_name? name

  if respond_to?(name)
    then intern send(name)
    else nil
  end
end