Module: ActiveHistory

Defined in:
lib/activehistory.rb,
lib/activehistory/version.rb,
lib/activehistory/exceptions.rb

Defined Under Namespace

Modules: Adapter Classes: Action, Connection, Event, Exception, Regard

Constant Summary collapse

UUIDV4 =
/^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
VERSION =
'5.1.0'

Class Method Summary collapse

Class Method Details

.configure(settings) ⇒ Object



9
10
11
12
# File 'lib/activehistory.rb', line 9

def self.configure(settings)
  self.logger = settings&.delete(:logger) || Logger.new(STDOUT)
  @@connection = ActiveHistory::Connection.new(settings)
end

.configured?Boolean



14
15
16
# File 'lib/activehistory.rb', line 14

def self.configured?
  class_variable_defined?(:@@connection) && !@@connection.nil?
end

.current_event(timestamp: nil) ⇒ Object



39
40
41
# File 'lib/activehistory.rb', line 39

def self.current_event(timestamp: nil)
  Thread.current[:activehistory_event]
end

.encapsulate(attributes_or_event = {}, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/activehistory.rb', line 22

def self.encapsulate(attributes_or_event={}, &block)
  if attributes_or_event.is_a?(ActiveHistory::Event)
    event = attributes_or_event
  else
    event = ActiveHistory::Event.new(attributes_or_event)
  end

  Thread.current[:activehistory_event] = event
  
  yield
ensure
  if configured? && Thread.current[:activehistory_event] && !Thread.current[:activehistory_event].actions.empty?
    Thread.current[:activehistory_event].save!
  end
  Thread.current[:activehistory_event] = nil
end

.urlObject



18
19
20
# File 'lib/activehistory.rb', line 18

def self.url
  @@connection.url
end