Class: Chimera::RedisObjectProxy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/chimera/redis_objects.rb

Direct Known Subclasses

Collection, Counter, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, extra_opts) ⇒ Base

Returns a new instance of Base.



48
49
50
51
52
53
54
55
56
# File 'lib/chimera/redis_objects.rb', line 48

def initialize(owner, name, extra_opts)
  unless owner and owner.id
    raise(Chimera::Errors::MissingId)
  end
  
  @owner = owner
  @name = name
  @extra_opts = extra_opts
end

Instance Attribute Details

#extra_optsObject

Returns the value of attribute extra_opts.



47
48
49
# File 'lib/chimera/redis_objects.rb', line 47

def extra_opts
  @extra_opts
end

#nameObject

Returns the value of attribute name.



47
48
49
# File 'lib/chimera/redis_objects.rb', line 47

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



47
48
49
# File 'lib/chimera/redis_objects.rb', line 47

def owner
  @owner
end

Instance Method Details

#connectionObject



58
59
60
# File 'lib/chimera/redis_objects.rb', line 58

def connection
  self.owner.class.connection(:redis)
end

#decode(val) ⇒ Object



74
75
76
77
78
# File 'lib/chimera/redis_objects.rb', line 74

def decode(val)
  return nil if val.nil?
  return "" if val == ""
  YAML.load(val)
end

#destroyObject



66
67
68
# File 'lib/chimera/redis_objects.rb', line 66

def destroy
  connection.del(self.key)
end

#encode(val) ⇒ Object



70
71
72
# File 'lib/chimera/redis_objects.rb', line 70

def encode(val)
  YAML.dump(val)
end

#keyObject



62
63
64
# File 'lib/chimera/redis_objects.rb', line 62

def key
  "#{self.class.to_s}::RedisObjects::#{name}::#{self.owner.id}"
end