Sha256: 366f6dd715ad648ee8ff6da3d01bf65217ffe8cd150ea7e46c00aeba72376811
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
module Mongoid module Genesis extend ActiveSupport::Concern def self.included(base) Object.const_set("#{base.name}Genesis", Class.new do include Mongoid::Document include Mongoid::Genesis::Storage embedded_in :alter, :class_name => base.name, :inverse_of => :genesis end) base.embeds_one :genesis, :class_name => "#{base.name}Genesis", :inverse_of => :alter end def init_genesis self.genesis = "#{self.class.name}Genesis".constantize.new end def read_attribute_genesis(field_name) source = (self.genesis and self.genesis.field_preserved?(field_name)) ? self.genesis : self return source.read_attribute field_name end def restore_genesis(field_name) self.genesis.restore field_name end def reverse_genesis self.genesis.reverse end def write_and_preserve_attribute(field_name, value) init_genesis if not self.genesis if value and self.genesis.read_attribute(field_name) == value self.restore_genesis(field_name) else self.genesis.preserve field_name self.write_attribute(field_name, value) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongoid-genesis-0.0.4 | lib/mongoid/genesis.rb |