Class: Rollout::Logging::Event

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature: nil, name:, data:, context: {}, created_at:) ⇒ Event

Returns a new instance of Event.



25
26
27
28
29
30
31
# File 'lib/rollout/logging.rb', line 25

def initialize(feature: nil, name:, data:, context: {}, created_at:)
  @feature = feature
  @name = name
  @data = data
  @context = context
  @created_at = created_at
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



17
18
19
# File 'lib/rollout/logging.rb', line 17

def context
  @context
end

#created_atObject (readonly)

Returns the value of attribute created_at.



17
18
19
# File 'lib/rollout/logging.rb', line 17

def created_at
  @created_at
end

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/rollout/logging.rb', line 17

def data
  @data
end

#featureObject (readonly)

Returns the value of attribute feature.



17
18
19
# File 'lib/rollout/logging.rb', line 17

def feature
  @feature
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/rollout/logging.rb', line 17

def name
  @name
end

Class Method Details

.from_raw(value, score) ⇒ Object



19
20
21
22
23
# File 'lib/rollout/logging.rb', line 19

def self.from_raw(value, score)
  hash = JSON.parse(value, symbolize_names: true)

  new(**hash.merge(created_at: Time.at(-score.to_f / 1_000_000)))
end

Instance Method Details

#==(other) ⇒ Object



47
48
49
50
51
52
# File 'lib/rollout/logging.rb', line 47

def ==(other)
  feature == other.feature \
    && name == other.name \
    && data == other.data \
    && created_at == other.created_at
end

#serializeObject



37
38
39
40
41
42
43
44
45
# File 'lib/rollout/logging.rb', line 37

def serialize
  JSON.dump(
    feature: @feature,
    name: @name,
    data: @data,
    context: @context,
    created_at: @created_at,
  )
end

#timestampObject



33
34
35
# File 'lib/rollout/logging.rb', line 33

def timestamp
  (@created_at.to_f * 1_000_000).to_i
end