Module: SuperSettings::Storage::Transaction

Included in:
HttpStorage, JSONStorage, MongoDBStorage, RedisStorage
Defined in:
lib/super_settings/storage/transaction.rb

Overview

This module provides support for transactions in storage models that don’t natively support transactions.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/super_settings/storage/transaction.rb', line 8

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#persisted=(value) ⇒ Object



47
48
49
# File 'lib/super_settings/storage/transaction.rb', line 47

def persisted=(value)
  @persisted = Coerce.boolean(value)
end

#persisted?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/super_settings/storage/transaction.rb', line 51

def persisted?
  !!@persisted
end

#save!Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/super_settings/storage/transaction.rb', line 55

def save!
  timestamp = Time.now
  self.updated_at ||= timestamp if respond_to?(:updated_at)
  self.created_at ||= (respond_to?(:updated_at) ? updated_at : timestamp)

  self.class.transaction do |changes|
    changes << self
  end

  true
end