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.



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
# File 'lib/probatio.rb', line 804

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.



801
802
803
# File 'lib/probatio.rb', line 801

def context
  @context
end

#deltaObject (readonly)

Returns the value of attribute delta.



800
801
802
# File 'lib/probatio.rb', line 800

def delta
  @delta
end

#errorObject (readonly)

Returns the value of attribute error.



801
802
803
# File 'lib/probatio.rb', line 801

def error
  @error
end

#groupObject (readonly)

Returns the value of attribute group.



801
802
803
# File 'lib/probatio.rb', line 801

def group
  @group
end

#leafObject (readonly)

Returns the value of attribute leaf.



801
802
803
# File 'lib/probatio.rb', line 801

def leaf
  @leaf
end

#leave_deltaObject

Returns the value of attribute leave_delta.



802
803
804
# File 'lib/probatio.rb', line 802

def leave_delta
  @leave_delta
end

#nameObject (readonly)

Returns the value of attribute name.



801
802
803
# File 'lib/probatio.rb', line 801

def name
  @name
end

#optsObject (readonly)

Returns the value of attribute opts.



801
802
803
# File 'lib/probatio.rb', line 801

def opts
  @opts
end

#tstampObject (readonly)

Returns the value of attribute tstamp.



800
801
802
# File 'lib/probatio.rb', line 800

def tstamp
  @tstamp
end

Instance Method Details

#delta_sObject



842
843
844
845
846
# File 'lib/probatio.rb', line 842

def delta_s

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

#depthObject



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

def depth; node.depth rescue 0; end

#determine_leave_deltaObject



835
836
837
838
839
840
# File 'lib/probatio.rb', line 835

def determine_leave_delta

  lev = Probatio.recorder_plugin.test_leave_event(node)

  lev && lev.leave_delta
end

#directionObject



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

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

#enter?Boolean

Returns:

  • (Boolean)


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

def enter?; direction == :enter; end

#leave?Boolean

Returns:

  • (Boolean)


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

def leave?; direction == :leave; end

#locationObject



848
849
850
851
852
# File 'lib/probatio.rb', line 848

def location

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

#nodeObject



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

def node; @leaf || @group; end

#node_full_nameObject

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



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

def node_full_name; node && node.full_name; end

#pathObject



854
855
856
857
# File 'lib/probatio.rb', line 854

def path

  node && node.path
end

#to_hObject



877
878
879
880
# File 'lib/probatio.rb', line 877

def to_h

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

#to_sObject



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/probatio.rb', line 859

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



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

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