Class: Andromeda::Impl::ProtoPlan

Inherits:
ConnectorBase show all
Extended by:
ClassAttr
Includes:
To_S
Defined in:
lib/andromeda/impl/proto_plan.rb

Direct Known Subclasses

Plan

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from To_S

short_s, #to_s

Methods inherited from ConnectorBase

#post, #post_local, #start

Constructor Details

#initialize(config = {}) ⇒ ProtoPlan

Returns a new instance of ProtoPlan.



45
46
47
48
49
50
# 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

Instance Attribute Details

#guideObject

Returns the value of attribute guide.



43
44
45
# File 'lib/andromeda/impl/proto_plan.rb', line 43

def guide
  @guide
end

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'lib/andromeda/impl/proto_plan.rb', line 42

def id
  @id
end

Class Method Details

.name_spot(*names) ⇒ Object



13
# File 'lib/andromeda/impl/proto_plan.rb', line 13

def self.name_spot(*names) ; name_attr_set '@spot_names', *names end

.signal_names(inherit = true) ⇒ Object



39
# 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) ⇒ Object



40
# File 'lib/andromeda/impl/proto_plan.rb', line 40

def self.signal_spot(*names) ; name_attr_set '@signal_names', *names end

.spot_attr(*names) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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) ⇒ Object



11
# 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 = {}) ⇒ Object



15
16
17
18
19
20
21
# 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) ⇒ Object



12
# 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) ⇒ Object



10
# File 'lib/andromeda/impl/proto_plan.rb', line 10

def self.spot_names(inherit = true) ; get_attr_set '@spot_names', inherit end

Instance Method Details

#>>(spot) ⇒ Object



153
154
155
156
157
# 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_nameObject



151
# File 'lib/andromeda/impl/proto_plan.rb', line 151

def current_name ;  tags[:name] end

#current_scopeObject



150
# File 'lib/andromeda/impl/proto_plan.rb', line 150

def current_scope ;  tags[:scope] end

#data_key(name, data) ⇒ Object

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



77
# File 'lib/andromeda/impl/proto_plan.rb', line 77

def data_key(name, data) ; name end

#data_tag(name, key, val, tags_in) ⇒ Object

Override to compute additional tags



89
# File 'lib/andromeda/impl/proto_plan.rb', line 89

def data_tag(name, key, val, tags_in) ; { name: name } end

#data_val(name, data) ⇒ Object

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



86
# File 'lib/andromeda/impl/proto_plan.rb', line 86

def data_val(name, data) ; data end

#destObject



160
# File 'lib/andromeda/impl/proto_plan.rb', line 160

def dest ; emit end

#entryObject



159
# File 'lib/andromeda/impl/proto_plan.rb', line 159

def entry ; enter end

#init_guideObject



57
# File 'lib/andromeda/impl/proto_plan.rb', line 57

def init_guide ; Guides.default end

#initialize_copy(other) ⇒ Object



52
53
54
55
# File 'lib/andromeda/impl/proto_plan.rb', line 52

def initialize_copy(other)
  @tags    = @tags.identical_copy
  @tags  ||= {}
end

#key_label(name, key) ⇒ Object

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



83
# File 'lib/andromeda/impl/proto_plan.rb', line 83

def key_label(name, key) ; key end

#key_spot(name, key) ⇒ Object

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



80
# File 'lib/andromeda/impl/proto_plan.rb', line 80

def key_spot(name, key) ; name end

#map_data(name, data) ⇒ Object

Override to map all incoming data, default to data



74
# File 'lib/andromeda/impl/proto_plan.rb', line 74

def map_data(name, data) ; data end

#muteObject



161
# File 'lib/andromeda/impl/proto_plan.rb', line 161

def mute ; @emit = nil end

#post_data(spot_, track_in, data, tags_in = {}) ⇒ Object

Raises:

  • (ArgumentError)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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 = {}) ⇒ Object



164
# 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) ⇒ Spot?

Returns public spot with name name if any, nil otherwise.

Returns:

  • (Spot, nil)

    public spot with name name if any, nil otherwise

Raises:

  • (ArgumentError)


130
131
132
133
134
135
136
137
138
# 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) ⇒ Boolean

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

Returns:

  • (Boolean)


92
# File 'lib/andromeda/impl/proto_plan.rb', line 92

def selects?(name, key, val, tags_in) ; true end

#signal_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


143
# File 'lib/andromeda/impl/proto_plan.rb', line 143

def signal_name?(name) ; signal_names.include? name end

#signal_namesObject



148
# File 'lib/andromeda/impl/proto_plan.rb', line 148

def signal_names ; self.class.signal_names end

#spot_attr_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


141
# File 'lib/andromeda/impl/proto_plan.rb', line 141

def spot_attr_name?(name) ; spot_attr_names.include? name end

#spot_attr_namesObject



146
# File 'lib/andromeda/impl/proto_plan.rb', line 146

def spot_attr_names ; self.class.spot_attr_names end

#spot_meth_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


142
# File 'lib/andromeda/impl/proto_plan.rb', line 142

def spot_meth_name?(name) ; spot_meth_names.include? name end

#spot_meth_namesObject



147
# File 'lib/andromeda/impl/proto_plan.rb', line 147

def spot_meth_names ; self.class.spot_meth_names end

#spot_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


140
# File 'lib/andromeda/impl/proto_plan.rb', line 140

def spot_name?(name) ; spot_names.include? name end

#spot_namesObject



145
# File 'lib/andromeda/impl/proto_plan.rb', line 145

def spot_names ; self.class.spot_names end

#tagsObject



59
# File 'lib/andromeda/impl/proto_plan.rb', line 59

def tags ; @tags end

#to_short_sObject



60
# File 'lib/andromeda/impl/proto_plan.rb', line 60

def to_short_s ; " id=#{id.to_short_s}t" end

#via(spot_name) ⇒ Object



162
# File 'lib/andromeda/impl/proto_plan.rb', line 162

def via(spot_name) ; entry.via(spot_name) end