Class: Redpear::Store::Value

Inherits:
Base
  • Object
show all
Defined in:
lib/redpear/store/value.rb

Direct Known Subclasses

Counter

Constant Summary

Constants inherited from Base

Base::IS_NIL, Base::IS_ONE, Base::IS_TRUE, Base::IS_ZERO, Base::PICK_FIRST, Base::TO_INT, Base::TO_SET

Instance Attribute Summary

Attributes inherited from Base

#conn, #key

Instance Method Summary collapse

Methods inherited from Base

#clear, #exists?, #expire, #expire_at, #expire_in, #initialize, #inspect, #purge!, temporary, #ttl, #type, #watch

Constructor Details

This class inherits a constructor from Redpear::Store::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *a, &b) ⇒ Object (protected)



71
72
73
74
# File 'lib/redpear/store/value.rb', line 71

def method_missing(method, *a, &b)
  base = (value || "")
  base.respond_to?(method) ? base.send(method, *a, &b) : super
end

Instance Method Details

#==(other) ⇒ Boolean

Comparator

Parameters:

  • other (String)

Returns:

  • (Boolean)

    true, if equals ‘other`



45
46
47
48
49
50
51
52
# File 'lib/redpear/store/value.rb', line 45

def ==(other)
  case value = self.value
  when Redis::Future
    value.instance_eval { @transformation = Kernel.lambda {|v| v == other } }
  else
    value == other
  end
end

#append(value) ⇒ Object Also known as: <<

Appends a ‘value`

Parameters:

  • value (Integer)

    The value to append



36
37
38
39
# File 'lib/redpear/store/value.rb', line 36

def append(value)
  conn.append(key, value)
  self
end

#getString

Returns the value.

Returns:

  • (String)

    the value



8
9
10
# File 'lib/redpear/store/value.rb', line 8

def get
  conn.get(key)
end

#nil?Boolean

Returns true, if value is nil.

Returns:

  • (Boolean)

    true, if value is nil



55
56
57
58
59
60
61
62
# File 'lib/redpear/store/value.rb', line 55

def nil?
  case value = self.value
  when Redis::Future
    value.instance_eval { @transformation = IS_NIL }
  else
    value.nil?
  end
end

#replace(*a) ⇒ Object

See Also:



29
30
31
# File 'lib/redpear/store/value.rb', line 29

def replace(*a)
  set(*a)
end

#respond_to?(method, *a) ⇒ Boolean

Returns true, if responds to ‘method`.

Returns:

  • (Boolean)

    true, if responds to ‘method`



65
66
67
# File 'lib/redpear/store/value.rb', line 65

def respond_to?(method, *a)
  super || (value || "").respond_to?(method, *a)
end

#set(value) ⇒ Object

Sets the value

Parameters:

  • value (String)

    the value to set



19
20
21
# File 'lib/redpear/store/value.rb', line 19

def set(value)
  conn.set(key, value)
end

#valueObject

See Also:



13
14
15
# File 'lib/redpear/store/value.rb', line 13

def value
  get
end

#value=(*a) ⇒ Object

See Also:



24
25
26
# File 'lib/redpear/store/value.rb', line 24

def value=(*a)
  set(*a)
end