Class: SuperSettings::Storage::MongoDBStorage::HistoryStorage

Inherits:
HistoryAttributes show all
Defined in:
lib/super_settings/storage/mongodb_storage.rb

Instance Attribute Summary

Attributes inherited from HistoryAttributes

#changed_by, #created_at, #deleted, #key, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HistoryAttributes

#deleted?, #initialize

Methods included from Attributes

#attributes=, #initialize

Constructor Details

This class inherits a constructor from SuperSettings::Storage::HistoryAttributes

Class Method Details

.create!(attributes) ⇒ Object



30
31
32
33
34
# File 'lib/super_settings/storage/mongodb_storage.rb', line 30

def create!(attributes)
  record = new(attributes)
  record.save!
  record
end

Instance Method Details

#as_bsonObject



49
50
51
52
53
54
55
56
57
# File 'lib/super_settings/storage/mongodb_storage.rb', line 49

def as_bson
  attributes = {
    value: value,
    changed_by: changed_by,
    created_at: created_at
  }
  attributes[:deleted] = true if deleted?
  attributes
end

#created_at=(value) ⇒ Object



37
38
39
# File 'lib/super_settings/storage/mongodb_storage.rb', line 37

def created_at=(value)
  super(TimePrecision.new(value, :millisecond).time)
end

#save!Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/super_settings/storage/mongodb_storage.rb', line 41

def save!
  raise ArgumentError.new("Missing key") if Coerce.blank?(key)

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