Class: Probatio::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/probatio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, details) ⇒ Event

Returns a new instance of Event.



923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
# File 'lib/probatio.rb', line 923

def initialize(name, details)

  @tstamp, @delta = Probatio.monow_and_delta

  @name = name.to_s

  details.each do |d|
    case d
    when Hash then @opts = d
    when Exception then @error = d
    when Probatio::Leaf then @leaf = d
    when Probatio::Group then @group = d
    when Probatio::Context then @context = d
    else fail ArgumentError.new("cannot fathom #{d.class} #{d.inspect}")
    end
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



920
921
922
# File 'lib/probatio.rb', line 920

def context
  @context
end

#deltaObject (readonly)

Returns the value of attribute delta.



919
920
921
# File 'lib/probatio.rb', line 919

def delta
  @delta
end

#errorObject (readonly)

Returns the value of attribute error.



920
921
922
# File 'lib/probatio.rb', line 920

def error
  @error
end

#groupObject (readonly)

Returns the value of attribute group.



920
921
922
# File 'lib/probatio.rb', line 920

def group
  @group
end

#leafObject (readonly)

Returns the value of attribute leaf.



920
921
922
# File 'lib/probatio.rb', line 920

def leaf
  @leaf
end

#leave_deltaObject

Returns the value of attribute leave_delta.



921
922
923
# File 'lib/probatio.rb', line 921

def leave_delta
  @leave_delta
end

#nameObject (readonly)

Returns the value of attribute name.



920
921
922
# File 'lib/probatio.rb', line 920

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



920
921
922
# File 'lib/probatio.rb', line 920

def opts
  @opts
end

#tstampObject (readonly)

Returns the value of attribute tstamp.



919
920
921
# File 'lib/probatio.rb', line 919

def tstamp
  @tstamp
end

Instance Method Details

#delta_sObject



961
962
963
964
965
# File 'lib/probatio.rb', line 961

def delta_s

  led = determine_leave_delta
  led ? Probatio.to_time_s(led) : '?'
end

#depthObject



943
# File 'lib/probatio.rb', line 943

def depth; node.depth rescue 0; end

#determine_leave_deltaObject



954
955
956
957
958
959
# File 'lib/probatio.rb', line 954

def determine_leave_delta

  lev = Probatio.recorder_plugin.test_leave_event(node)

  lev && lev.leave_delta
end

#directionObject



941
# File 'lib/probatio.rb', line 941

def direction; @direction ||= name.split('_').last.to_sym; end

#enter?Boolean

Returns:

  • (Boolean)


951
# File 'lib/probatio.rb', line 951

def enter?; direction == :enter; end

#leave?Boolean

Returns:

  • (Boolean)


952
# File 'lib/probatio.rb', line 952

def leave?; direction == :leave; end

#locationObject



967
968
969
970
971
# File 'lib/probatio.rb', line 967

def location

  (error && error.respond_to?(:location) && error.location) ||
  (node && node.location)
end

#nodeObject



942
# File 'lib/probatio.rb', line 942

def node; @leaf || @group; end

#node_full_nameObject

which, in the case of assertion != self.node.type …



949
# File 'lib/probatio.rb', line 949

def node_full_name; node && node.full_name; end

#pathObject



973
974
975
976
# File 'lib/probatio.rb', line 973

def path

  node && node.path
end

#to_hObject



996
997
998
999
# File 'lib/probatio.rb', line 996

def to_h

  { n: name, p: location[0], l: location[1], t: delta_s }
end

#to_sObject



978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# File 'lib/probatio.rb', line 978

def to_s

  led = determine_leave_delta

  o = StringIO.new
  o << "<event"
  o << "\n  name=#{name.inspect}"
  o << "\n  node=#{node.full_name.inspect}" if node
  o << "\n  node_type=#{node.type.inspect}" if node
  o << "\n  error=#{error.to_s.inspect}" if error
  o << "\n  location=#{location.map(&:to_s).join(':').inspect}" if node
  o << "\n  delta=\"#{Probatio.to_time_s(delta)}\"" if delta
  o << "\n  leave_delta=\"#{Probatio.to_time_s(led)}\"" if led
  o << " />"

  o.string
end

#typeObject



945
# File 'lib/probatio.rb', line 945

def type; @name.split('_').first; end