Class: AetherObservatory::EventBase

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::AttributeAssignment, ActiveModel::Attributes
Defined in:
lib/aether_observatory/event_base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ EventBase

Returns a new instance of EventBase.



56
57
58
59
# File 'lib/aether_observatory/event_base.rb', line 56

def initialize(attributes = {})
  super()
  assign_attributes(attributes) if attributes
end

Class Method Details

.create(**attributes) ⇒ Object



18
19
20
21
22
# File 'lib/aether_observatory/event_base.rb', line 18

def create(**attributes)
  backend.instrument new(**attributes)

  nil
end

.event_name(value = nil, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/aether_observatory/event_base.rb', line 31

def event_name(value = nil, &block)
  event_names << -> { value } if value.present?
  event_names << block if block.present?

  nil
end

.event_namesObject



42
43
44
# File 'lib/aether_observatory/event_base.rb', line 42

def event_names
  @event_names ||= []
end

.event_names_with_prefixObject



38
39
40
# File 'lib/aether_observatory/event_base.rb', line 38

def event_names_with_prefix
  event_names.map { |event_name| [event_prefix, event_name] }
end

.event_prefix(value = nil, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/aether_observatory/event_base.rb', line 24

def event_prefix(value = nil, &block)
  @event_prefix = -> { value } if value.present?
  @event_prefix = block if block.present?

  @event_prefix
end

.inherited(subclass) ⇒ Object



13
14
15
16
# File 'lib/aether_observatory/event_base.rb', line 13

def inherited(subclass)
  super
  subclass.event_prefix(&event_prefix)
end

.logger(value = nil) ⇒ Object



46
47
48
49
50
# File 'lib/aether_observatory/event_base.rb', line 46

def logger(value = nil)
  @logger = value if value.present?

  @logger || AetherObservatory.config.logger || Logger.new(nil)
end

Instance Method Details

#namesObject



61
62
63
64
65
66
# File 'lib/aether_observatory/event_base.rb', line 61

def names
  prefix = instance_exec(&self.class.event_prefix) if self.class.event_prefix
  self.class.event_names.map do |event_name|
    [prefix, instance_exec(&event_name)].compact.join(".")
  end
end