Sha256: d816d42db0d59eb420a82afc1e8ad176ee550a861e8d1f272ad23895ec7f4dde

Contents?: true

Size: 851 Bytes

Versions: 5

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

module Mnemosyne
  class Span
    attr_reader :uuid, :name, :start, :finish, :meta, :type

    def initialize(name, start: false, finish: false, meta: {})
      @type = nil
      @name = name
      @meta = meta
      @uuid = ::SecureRandom.uuid

      @start  = start
      @finish = finish
    end

    def start!
      raise 'Already started' if @start

      @start = ::Mnemosyne::Clock.tick

      self
    end

    def finish!(oneshot: false)
      raise 'Already finished' if @finish

      @finish = ::Mnemosyne::Clock.tick

      if oneshot
        @start = @finish unless @start
        @type  = :oneshot
      end

      self
    end

    def serialize
      {
        uuid: uuid,
        name: name,
        type: type,
        start: start,
        stop: finish,
        meta: meta
      }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mnemosyne-ruby-1.3.0 lib/mnemosyne/span.rb
mnemosyne-ruby-1.2.1 lib/mnemosyne/span.rb
mnemosyne-ruby-1.2.0 lib/mnemosyne/span.rb
mnemosyne-ruby-1.1.0 lib/mnemosyne/span.rb
mnemosyne-ruby-1.1.0.rc1 lib/mnemosyne/span.rb