Class: Restruct::Structure

Inherits:
Object
  • Object
show all
Defined in:
lib/restruct/structure.rb

Direct Known Subclasses

Array, Hash, Set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Structure

Returns a new instance of Structure.



6
7
8
9
# File 'lib/restruct/structure.rb', line 6

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/restruct/structure.rb', line 4

def id
  @id
end

#redisObject (readonly)

Returns the value of attribute redis.



4
5
6
# File 'lib/restruct/structure.rb', line 4

def redis
  @redis
end

Instance Method Details

#==(object) ⇒ Object Also known as: eql?



11
12
13
14
15
# File 'lib/restruct/structure.rb', line 11

def ==(object)
  object.class == self.class && 
  object.id == id && 
  object.redis == redis
end

#destroyObject



27
28
29
# File 'lib/restruct/structure.rb', line 27

def destroy
  redis.call 'DEL', id
end

#dumpObject



18
19
20
# File 'lib/restruct/structure.rb', line 18

def dump
  redis.call 'DUMP', id
end

#restore(dump) ⇒ Object



22
23
24
25
# File 'lib/restruct/structure.rb', line 22

def restore(dump)
  destroy
  redis.call 'RESTORE', id, 0, dump
end