Sha256: c017dc47ac58d744422f2bae218b3ad8b0f867c7a5777c6ea459f2cf8ffb48f0

Contents?: true

Size: 667 Bytes

Versions: 4

Compression:

Stored size: 667 Bytes

Contents

module Restruct
  class Structure

    attr_reader :connection, :id

    def initialize(options={})
      @connection = options[:connection] || Restruct.connection
      @id = Id.new options[:id] || Restruct.generate_id
    end

    def ==(object)
      object.class == self.class && 
      object.id == id && 
      object.connection == connection
    end
    alias_method :eql?, :==

    def dump
      connection.call 'DUMP', id
    end

    def restore(dump)
      destroy
      connection.lazy 'RESTORE', id, 0, dump
    end

    def destroy
      connection.lazy 'DEL', id
    end

    def exists?
      connection.call('EXISTS', id) == 1
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restruct-1.1.0 lib/restruct/structure.rb
restruct-1.0.0 lib/restruct/structure.rb
restruct-0.2.0 lib/restruct/structure.rb
restruct-0.1.0 lib/restruct/structure.rb