Class: ODBA::IdServer
- Includes:
- Persistable
- Defined in:
- lib/odba/id_server.rb
Constant Summary collapse
- ODBA_SERIALIZABLE =
['@ids']
- ODBA_EXCLUDE_VARS =
['@mutex']
Constants included from Persistable
Persistable::Exact, Persistable::Find, Persistable::ODBA_INDEXABLE, Persistable::ODBA_PREDEFINE_EXCLUDE_VARS, Persistable::ODBA_PREDEFINE_SERIALIZABLE, Persistable::ODBA_PREFETCH
Instance Attribute Summary
Attributes included from Persistable
#odba_id, #odba_name, #odba_persistent, #odba_prefetch
Instance Method Summary collapse
-
#initialize ⇒ IdServer
constructor
A new instance of IdServer.
- #next_id(key, startval = 1) ⇒ Object
Methods included from Persistable
#==, append_features, #dup, #eql?, #odba_add_observer, #odba_collection, #odba_cut_connection, #odba_delete, #odba_delete_observer, #odba_delete_observers, #odba_dup, #odba_exclude_vars, #odba_indexable?, #odba_isolated_dump, #odba_isolated_store, #odba_isolated_stub, #odba_isolated_twin, #odba_notify_observers, #odba_observers, #odba_potentials, #odba_prefetch?, #odba_replace!, #odba_replace_persistables, #odba_replace_stubs, #odba_restore, #odba_serializables, #odba_snapshot, #odba_store, #odba_store_unsaved, #odba_stubize, #odba_take_snapshot, #odba_target_ids, #odba_unsaved?, #odba_unsaved_neighbors, sanitize
Constructor Details
#initialize ⇒ IdServer
Returns a new instance of IdServer.
12 13 14 |
# File 'lib/odba/id_server.rb', line 12 def initialize @ids = {} end |
Instance Method Details
#next_id(key, startval = 1) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/odba/id_server.rb', line 15 def next_id(key, startval=1) @mutex ||= Mutex.new res = nil @mutex.synchronize { @ids[key] ||= (startval - 1) res = @ids[key] += 1 } odba_store res end |