Module: Ephemeron

Defined in:
lib/ephemeron.rb,
lib/ephemeron/errors.rb,
lib/ephemeron/railtie.rb,
lib/ephemeron/version.rb,
lib/ephemeron/settings.rb,
lib/ephemeron/store/update.rb,
lib/ephemeron/store/convert.rb,
lib/ephemeron/store/finders.rb,
lib/ephemeron/writers/store.rb,
lib/ephemeron/logger/convert.rb,
lib/ephemeron/logger/finders.rb,
lib/ephemeron/writers/logger.rb,
lib/ephemeron/validators/store.rb,
lib/ephemeron/store/allow_fetch.rb,
lib/ephemeron/writers/callbacks.rb,
lib/ephemeron/addons/model_addons.rb,
lib/ephemeron/writers/thread_store.rb,
lib/ephemeron/validators/before_save.rb,
lib/ephemeron/validators/store/unused.rb,
lib/ephemeron/addons/controller_addons.rb,
lib/ephemeron/validators/store_element.rb,
lib/ephemeron/validators/store/allowed_but_unsaved.rb

Defined Under Namespace

Modules: ControllerAddons, ModelAddons, Validators Classes: Callbacks, Logger, LoggerError, PersistenceError, Railtie, Settings, Store, StoreError, ThreadStore

Constant Summary collapse

VERSION =
'0.6.1'

Class Method Summary collapse

Class Method Details

.add(model, as: nil) ⇒ Object



45
46
47
# File 'lib/ephemeron.rb', line 45

def add(model, as: nil)
  Store.add model, as: as
end

.after_save!(&block) ⇒ Object



87
88
89
# File 'lib/ephemeron.rb', line 87

def after_save!(&block)
  Callbacks.add block
end

.allow_fetch!(model_or_key) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/ephemeron.rb', line 70

def allow_fetch!(model_or_key)
  model = if model_or_key.is_a?(String)
            Ephemeron.get(model_or_key)
          else
            model_or_key
          end
  model.tap { |m| Logger.log m, :fetch_allowed }
end

.allow_save!(model) ⇒ Object



79
80
81
# File 'lib/ephemeron.rb', line 79

def allow_save!(model)
  model.tap { |m| Logger.log m, :save_allowed }
end

.configureObject



30
31
32
33
34
35
# File 'lib/ephemeron.rb', line 30

def configure
  Ephemeron::Settings::CONFIG.new.tap do |config|
    yield config
    Ephemeron::Settings.configure config
  end
end

.finishObject



91
92
93
94
95
96
97
98
# File 'lib/ephemeron.rb', line 91

def finish
  if Store.aliases[nil] != :abort
    Store.validate
    Store.persist
    Callbacks.call
  end
  reset
end

.get(key) ⇒ Object



56
57
58
# File 'lib/ephemeron.rb', line 56

def get(key)
  Store.get key
end

.logsObject



41
42
43
# File 'lib/ephemeron.rb', line 41

def logs
  Logger.logs
end

.proxyObject



49
50
51
52
53
54
# File 'lib/ephemeron.rb', line 49

def proxy
  Logger.log nil, :proxy_start
  res = yield
  Logger.log nil, :proxy_end
  res
end

.resetObject



104
105
106
107
108
109
# File 'lib/ephemeron.rb', line 104

def reset
  Store.reset
  Logger.reset
  Callbacks.reset
  true
end

.skip_save!(model) ⇒ Object



83
84
85
# File 'lib/ephemeron.rb', line 83

def skip_save!(model)
  Logger.log model, :skip_save
end

.stateObject



37
38
39
# File 'lib/ephemeron.rb', line 37

def state
  Store.store
end

.stopObject



100
101
102
# File 'lib/ephemeron.rb', line 100

def stop
  Store.aliases[nil] = :abort
end

.used(model_s) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/ephemeron.rb', line 60

def used(model_s)
  log_used = ->(model) { Logger.log model, :used }
  if model_s.is_a? ActiveRecord::Base
    log_used.call model_s
  else
    model_s.each(&log_used)
  end
  model_s
end