Class: MassiveRecord::ORM::IdFactory::AtomicIncrementation
- Includes:
- MassiveRecord::ORM::IdFactory
- Defined in:
- lib/massive_record/orm/id_factory/atomic_incrementation.rb
Overview
A factory class for unique IDs for any given tables.
Usage:
AtomicIncrementation.next_for(:cars) # => 1
AtomicIncrementation.next_for(:cars) # => 2
AtomicIncrementation.next_for(AClassRespondingToTableName) # => 1
AtomicIncrementation.next_for("a_class_responding_to_table_names") # => 2
Storage:
Stored in id_factories table, under column family named tables.
Field name equals to tables it has generated ids for, and it's
values is integers (if the adapter supports it).
Constant Summary collapse
- COLUMN_FAMILY_FOR_TABLES =
:tables
- ID =
"id_factory"
Class Method Summary collapse
-
.instance ⇒ Object
Returns the factory, singleton class.
Instance Method Summary collapse
Methods included from MassiveRecord::ORM::IdFactory
Methods included from Schema::TableInterface
Methods inherited from Base
#==, ===, base_class, #clone, #freeze, #frozen?, #hash, #id=, inheritance_attribute, #init_with, #initialize, #inspect, #raw_data, #readonly!, #readonly?, #reinit_with, reset_table_name_configuration!, set_inheritance_attribute, table_name, table_name=, table_name_without_pre_and_suffix, #update_raw_data_for_column_family
Constructor Details
This class inherits a constructor from MassiveRecord::ORM::Base
Class Method Details
.instance ⇒ Object
Returns the factory, singleton class. It will be a reloaded version each time instance is retrieved, or else it will fetch self from the database, or if all other fails return a new of self.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/massive_record/orm/id_factory/atomic_incrementation.rb', line 38 def self.instance if table_exists? begin if @instance @instance.reload # If, for some reason, the record has been removed. Will be rescued and set to nil else @instance = find(ID) end rescue RecordNotFound @instance = nil end end @instance = new unless @instance @instance end |
Instance Method Details
#id ⇒ Object
57 58 59 |
# File 'lib/massive_record/orm/id_factory/atomic_incrementation.rb', line 57 def id ID end |