Sha256: 8b31dbfa160ca98b036a9ade0e6a5b10789a089c81c97a67eec0604707174bdc

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Mongoid
  module Genesis
    module Storage
      def field_preserved?(field_name)
        self.attribute_present? field_name
      end

      def preserve(field_name)
        self.write_attribute(field_name, self.alter.read_attribute(field_name)) if not field_preserved? field_name
      end

      def restore(field_name)
        if field_preserved? field_name
          self.alter.write_attribute(field_name, self.read_attribute(field_name))
          self.remove_attribute(field_name)
        end
      end

      def reverse
        self.attributes.each do |name, value|
          if not ['_id', '_type'].include? name
            buffer = self.alter.read_attribute(name)

            self.alter.write_attribute(name, self.read_attribute(name))
            self.write_attribute(name, buffer)
          end
        end
      end

      def method_missing(*args, &block)
        if self.alter.respond_to? args[0].to_s
          self.read_attribute args[0]
        else
          raise NoMethodError.new("undefined local variable or method '#{args.first}' for #{self.class}")
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-genesis-0.0.4 lib/mongoid/genesis/storage.rb
mongoid-genesis-0.0.3 lib/mongoid/genesis/storage.rb
mongoid-genesis-0.0.2 lib/mongoid/genesis/storage.rb
mongoid-genesis-0.0.1 lib/mongoid/genesis/storage.rb