Class: MongoSequence
- Inherits:
-
Object
- Object
- MongoSequence
- Defined in:
- lib/mongo_sequence.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
- #current ⇒ Object
- #current=(integer) ⇒ Object
-
#initialize(name) ⇒ MongoSequence
constructor
A new instance of MongoSequence.
- #next ⇒ Object
Constructor Details
#initialize(name) ⇒ MongoSequence
Returns a new instance of MongoSequence.
29 30 31 |
# File 'lib/mongo_sequence.rb', line 29 def initialize(name) @name = name.to_s end |
Class Attribute Details
.database ⇒ Object
8 9 10 11 12 |
# File 'lib/mongo_sequence.rb', line 8 def database return @database if @database return MongoMapper.database if defined?(MongoMapper) && MongoMapper.database return Mongoid.database if defined?(Mongoid) && Mongoid.database end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/mongo_sequence.rb', line 27 def name @name end |
Class Method Details
.[](name) ⇒ Object
18 19 20 |
# File 'lib/mongo_sequence.rb', line 18 def [](name) new(name) end |
.[]=(name, integer) ⇒ Object
22 23 24 |
# File 'lib/mongo_sequence.rb', line 22 def []=(name, integer) self[name].current = integer end |
.collection ⇒ Object
14 15 16 |
# File 'lib/mongo_sequence.rb', line 14 def collection database['sequences'] end |
Instance Method Details
#collection ⇒ Object
33 34 35 |
# File 'lib/mongo_sequence.rb', line 33 def collection MongoSequence.collection end |
#current ⇒ Object
41 42 43 |
# File 'lib/mongo_sequence.rb', line 41 def current current_after_update(:$set => {}) # noop that works end |
#current=(integer) ⇒ Object
45 46 47 |
# File 'lib/mongo_sequence.rb', line 45 def current=(integer) current_after_update(:current => integer) end |
#next ⇒ Object
37 38 39 |
# File 'lib/mongo_sequence.rb', line 37 def next current_after_update(:$inc => { :current => 1 }) end |