Class: Rodbot::Db
- Inherits:
-
Object
- Object
- Rodbot::Db
- Defined in:
- lib/rodbot/db.rb,
lib/rodbot/db/hash.rb,
lib/rodbot/db/redis.rb
Overview
Uniform key/value database interface for various backends
Keys can be namespaced using the colon as separator:
-
‘color’ - color key without namespace
-
‘bike:color’ - color key within the bike namespace
-
‘vehicle:bike:color’ - color key within… you get the idea
Furthermore, keys can be entered either as colon separated keys or as list of symbols. The following are therefore equivalent:
Rodbot.db.get('vehicle:bike:color')
Rodbot.db.get(:vehicle, :bike, :color)
Same goes for the star wildcard which is only allowed last:
Rodbot.db.scan('vehicle:*')
Rodbot.db.scan(:vehicle, :*)
The interface is simple and straightforward:
Please note that JSON is used to serialize which has an influence on what you get back after deserialization:
-
Primitive types such as String, Integer or TrueClass are preserved.
-
Any other object is converted to String, incuding…
-
Symbol values are converted to String
-
Symbol elements in an array are converted to String
-
Symbol values in a hash are converted to String
However, hash keys are always converted to Symbol - mainly because Rubyland favours Symbol keys over String keys for visual reasons.
Defined Under Namespace
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ Db
constructor
A new instance of Db.
Constructor Details
#initialize(url) ⇒ Db
Returns a new instance of Db.
76 77 78 79 |
# File 'lib/rodbot/db.rb', line 76 def initialize(url) @url = url extend "rodbot/db/#{url.split('://').first}".constantize end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
73 74 75 |
# File 'lib/rodbot/db.rb', line 73 def url @url end |