Module: Rufus::Tokyo::TokyoContainerMixin
- Included in:
- Table
- Defined in:
- lib/rufus/tokyo/base.rb
Overview
Some constants shared by most of Tokyo Cabinet APIs
(Used only by rufus/tokyo/cabinet/table for now)
Constant Summary collapse
- OREADER =
some Tokyo constants
1 << 0
- OWRITER =
open as a reader
1 << 1
- OCREAT =
open as a writer
1 << 2
- OTRUNC =
writer creating
1 << 3
- ONOLCK =
writer truncating
1 << 4
- OLCKNB =
open without locking
1 << 5
- OTSYNC =
lock without blocking
1 << 6
Instance Method Summary collapse
-
#compute_open_mode(params) ⇒ Object
Given params (array or hash), computes the open mode (an int) for the Tokyo Cabinet object.
-
#params_to_h(params) ⇒ Object
Makes sure that a set of parameters is a hash (will transform an array into a hash if necessary).
Instance Method Details
#compute_open_mode(params) ⇒ Object
Given params (array or hash), computes the open mode (an int) for the Tokyo Cabinet object.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rufus/tokyo/base.rb', line 77 def compute_open_mode (params) params = params_to_h(params) { :read => OREADER, :reader => OREADER, :write => OWRITER, :writer => OWRITER, :create => OCREAT, :truncate => OTRUNC, :no_lock => ONOLCK, :lock_no_block => OLCKNB, :sync_every => OTSYNC }.inject(0) { |r, (k, v)| r = r | v if params[k]; r } end |
#params_to_h(params) ⇒ Object
Makes sure that a set of parameters is a hash (will transform an array into a hash if necessary)
66 67 68 69 70 71 |
# File 'lib/rufus/tokyo/base.rb', line 66 def params_to_h (params) params.is_a?(Hash) ? params : Array(params).inject({}) { |h, e| h[e] = true; h } end |