Module: CamelTrail

Defined in:
lib/camel_trail.rb,
lib/camel_trail/config.rb,
lib/camel_trail/engine.rb,
lib/camel_trail/version.rb,
lib/camel_trail/recordable.rb,
app/models/camel_trail/history.rb,
lib/camel_trail/entry_presenter.rb,
lib/camel_trail/yaml_unsafe_coder.rb,
app/models/camel_trail/encrypted_history.rb,
app/models/camel_trail/application_record.rb

Defined Under Namespace

Modules: Config, Recordable, YAMLUnsafeCoder Classes: ApplicationRecord, EncryptedHistory, Engine, EntryPresenter, History

Constant Summary collapse

VERSION =

The current version of the gem.

"1.0.0"

Class Method Summary collapse

Class Method Details

.configObject

Allows to set configurion for CamelTrail

CamelTrail.config do configs to be set end



21
22
23
# File 'lib/camel_trail.rb', line 21

def config(...)
  Config.config(...)
end

.for(object, encrypted: false, in_natural_order: false) ⇒ Array<CamelTrail::EntryPresenter>

A collection of the history entries associated with the object

Parameters:

  • object (#id)

    the object recording a history

Returns:



53
54
55
56
57
58
59
60
# File 'lib/camel_trail.rb', line 53

def for(object, encrypted: false, in_natural_order: false)
  klass = encrypted ? CamelTrail::EncryptedHistory : CamelTrail::History

  history_collection = in_natural_order ? klass.for_source(object).in_natural_order : klass.for_source(object)
  history_collection.to_a.map do |history|
    CamelTrail::EntryPresenter.new(history)
  end
end

.record!(object, activity, changes, user_id, note = nil, encrypted: false) ⇒ Object

rubocop:disable Metrics/ParameterLists



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/camel_trail.rb', line 36

def record!(object, activity, changes, user_id, note = nil, encrypted: false)
  klass = encrypted ? CamelTrail::EncryptedHistory : CamelTrail::History

  history = klass.for_source(object).create!(
    source_changes: changes,
    activity: activity,
    user_id: user_id,
    note: note
  )
  EntryPresenter.new(history)
end