Module: Journaled

Defined in:
app/models/journaled/audit_log/event.rb,
lib/journaled.rb,
lib/journaled/engine.rb,
lib/journaled/errors.rb,
lib/journaled/current.rb,
lib/journaled/version.rb,
lib/journaled/audit_log.rb,
lib/journaled/connection.rb,
lib/journaled/transaction_ext.rb,
app/jobs/journaled/delivery_job.rb,
app/jobs/journaled/application_job.rb

Overview

FIXME: This cannot be included in lib/ because Journaled::Event is autoloaded via app/models

Autoloading Journaled::Event isn't strictly necessary, and for compatibility it would
make sense to move it to lib/.

Defined Under Namespace

Modules: Actor, AuditLog, Changes, Connection, Event, RelationChangeProtection, TransactionExt Classes: ActorUriProvider, ApplicationJob, Change, ChangeDefinition, ChangeWriter, Current, DeliveryJob, Engine, NotTrulyExceptionalError, TransactionSafetyError, Writer

Constant Summary collapse

SUPPORTED_QUEUE_ADAPTERS =
%w(delayed delayed_job good_job que).freeze
VERSION =
"5.3.2"

Class Method Summary collapse

Class Method Details

.actor_uriObject



51
52
53
# File 'lib/journaled.rb', line 51

def self.actor_uri
  Journaled::ActorUriProvider.instance.actor_uri
end

.commit_hashObject



47
48
49
# File 'lib/journaled.rb', line 47

def self.commit_hash
  ENV.fetch('GIT_COMMIT')
end

.detect_queue_adapter!Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/journaled.rb', line 59

def self.detect_queue_adapter!
  unless SUPPORTED_QUEUE_ADAPTERS.include?(queue_adapter)
    raise <<~MSG
      Journaled has detected an unsupported ActiveJob queue adapter: `:#{queue_adapter}`

      Journaled jobs must be enqueued transactionally to your primary database.

      Please install the appropriate gems and set `queue_adapter` to one of the following:
      #{SUPPORTED_QUEUE_ADAPTERS.map { |a| "- `:#{a}`" }.join("\n")}

      Read more at https://github.com/Betterment/journaled
    MSG
  end
end

.development_or_test?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/journaled.rb', line 35

def self.development_or_test?
  %w(development test).include?(Rails.env)
end

.enabled?Boolean

Returns:

  • (Boolean)


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

def self.enabled?
  ['0', 'false', false, 'f', ''].exclude?(ENV.fetch('JOURNALED_ENABLED', !development_or_test?))
end

.queue_adapterObject



55
56
57
# File 'lib/journaled.rb', line 55

def self.queue_adapter
  job_base_class_name.constantize.queue_adapter_name
end

.schema_providersObject



43
44
45
# File 'lib/journaled.rb', line 43

def self.schema_providers
  @schema_providers ||= [Journaled::Engine, Rails]
end

.tag!(**tags) ⇒ Object



82
83
84
# File 'lib/journaled.rb', line 82

def self.tag!(**tags)
  Current.tags = Current.tags.merge(tags)
end

.tagged(**tags) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/journaled.rb', line 74

def self.tagged(**tags)
  existing_tags = Current.tags
  tag!(**tags)
  yield
ensure
  Current.tags = existing_tags
end

.transactional_batching_enabled?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/journaled.rb', line 23

def self.transactional_batching_enabled?
  Thread.current[:journaled_transactional_batching_enabled] || @@transactional_batching_enabled
end

.with_transactional_batchingObject



27
28
29
30
31
32
33
# File 'lib/journaled.rb', line 27

def self.with_transactional_batching
  value_was = Thread.current[:journaled_transactional_batching_enabled]
  Thread.current[:journaled_transactional_batching_enabled] = true
  yield
ensure
  Thread.current[:journaled_transactional_batching_enabled] = value_was
end