Class: Hooksmith::Config::EventStore

Inherits:
Object
  • Object
show all
Defined in:
lib/hooksmith/config/event_store.rb

Overview

EventStore holds settings for optional event persistence.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventStore

Returns a new instance of EventStore.



16
17
18
19
20
21
22
# File 'lib/hooksmith/config/event_store.rb', line 16

def initialize
  @enabled = false
  # No default model in the gem; applications should provide their own model
  @model_class_name = nil
  @record_timing = :before
  @mapper = default_mapper
end

Instance Attribute Details

#enabledObject

Whether persistence is enabled.



8
9
10
# File 'lib/hooksmith/config/event_store.rb', line 8

def enabled
  @enabled
end

#mapperObject

Proc to map provider/event/payload to attributes persisted



12
13
14
# File 'lib/hooksmith/config/event_store.rb', line 12

def mapper
  @mapper
end

#model_class_nameObject

Class name of the model used to persist events. Must respond to .create!(attrs)



10
11
12
# File 'lib/hooksmith/config/event_store.rb', line 10

def model_class_name
  @model_class_name
end

#record_timingObject

When to record: :before, :after, or :both



14
15
16
# File 'lib/hooksmith/config/event_store.rb', line 14

def record_timing
  @record_timing
end

Instance Method Details

#model_classObject



24
25
26
27
28
29
30
# File 'lib/hooksmith/config/event_store.rb', line 24

def model_class
  return nil if model_class_name.nil?

  Object.const_get(model_class_name)
rescue NameError
  nil
end