Class: Andromeda::Kit::Tee

Inherits:
Plan show all
Defined in:
lib/andromeda/kit.rb

Instance Attribute Summary collapse

Attributes inherited from Plan

#error_level, #log, #marker, #nick, #trace_enter, #trace_exit

Attributes inherited from Impl::ProtoPlan

#guide, #id

Instance Method Summary collapse

Methods inherited from Plan

#pool, #tap, #to_short_s

Methods inherited from Impl::ProtoPlan

#>>, #current_name, #current_scope, #data_key, #data_tag, #data_val, #dest, #entry, #init_guide, #key_label, #key_spot, #map_data, #mute, name_spot, #post_data, #post_to, #public_spot, #selects?, #signal_name?, signal_names, #signal_names, signal_spot, spot_attr, #spot_attr_name?, #spot_attr_names, spot_attr_names, spot_meth, #spot_meth_name?, spot_meth_names, #spot_meth_names, #spot_name?, #spot_names, spot_names, #tags, #to_short_s, #via

Methods included from Impl::To_S

short_s, #to_s, #to_short_s

Methods inherited from Impl::ConnectorBase

#post, #post_local, #start

Constructor Details

#initialize(config = {}) ⇒ Tee

Returns a new instance of Tee.



47
48
49
50
51
52
53
# File 'lib/andromeda/kit.rb', line 47

def initialize(config = {})
  config = { nick: config } unless config.is_a? Hash || config.is_a?(Spot)
  config = { other: config } unless config.is_a? Hash
  super config

  @level ||= :info
end

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



45
46
47
# File 'lib/andromeda/kit.rb', line 45

def delay
  @delay
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

Instance Method Details

#initialize_copy(other) ⇒ Object



55
56
57
58
# File 'lib/andromeda/kit.rb', line 55

def initialize_copy(other)
  @level = other.level.identical_copy
  @delay = other.delay.identical_copy
end

#on_enter(key, val) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/andromeda/kit.rb', line 60

def on_enter(key, val)
  log_   = log
  level_ = level
  sleep delay.to_i if delay
  if log_ && level_
    cur_name = current_name
    key_str  = Andromeda::Impl::To_S.short_s key
    val_str  = Andromeda::Impl::To_S.short_s val
    log_str  = "#{to_s}.#{cur_name}(#{key_str}, #{val_str})"
    tags.each_pair { |k, v| log_str << " #{k}=#{Andromeda::Impl::To_S.short_s(v)}" }
    log_str << " tid=0x#{Thread.current.object_id.to_s(16)}"
    log_.send level, log_str
  end
  other_ = other
  other_ << val if other_
  super key, val
end