Class: EntityStore::ExternalStore
- Inherits:
-
Object
- Object
- EntityStore::ExternalStore
- Includes:
- Mongo
- Defined in:
- lib/mongo_entity_store/external_store.rb
Class Attribute Summary collapse
-
.connect_timeout ⇒ Object
writeonly
Sets the attribute connect_timeout.
-
.connection_profile ⇒ Object
Returns the value of attribute connection_profile.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(entity_type, event) ⇒ Object
- #collection ⇒ Object
- #ensure_indexes ⇒ Object
-
#get_events(since, type = nil, max_items = 100) ⇒ Object
Public - get events since a Time or ID.
- #open ⇒ Object
Class Attribute Details
.connect_timeout=(value) ⇒ Object (writeonly)
Sets the attribute connect_timeout
10 11 12 |
# File 'lib/mongo_entity_store/external_store.rb', line 10 def connect_timeout=(value) @connect_timeout = value end |
.connection_profile ⇒ Object
Returns the value of attribute connection_profile.
9 10 11 |
# File 'lib/mongo_entity_store/external_store.rb', line 9 def connection_profile @connection_profile end |
Class Method Details
.connection ⇒ Object
12 13 14 |
# File 'lib/mongo_entity_store/external_store.rb', line 12 def connection @_connection ||= Mongo::MongoClient.from_uri(ExternalStore.connection_profile, :connect_timeout => EntityStore::Config.connect_timeout) end |
.database ⇒ Object
16 17 18 |
# File 'lib/mongo_entity_store/external_store.rb', line 16 def database @_database ||= ExternalStore.connection_profile.split('/').last end |
Instance Method Details
#add_event(entity_type, event) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/mongo_entity_store/external_store.rb', line 33 def add_event(entity_type, event) collection.insert({ '_entity_type' => entity_type, '_type' => event.class.name }.merge(event.attributes) ) end |
#collection ⇒ Object
25 26 27 |
# File 'lib/mongo_entity_store/external_store.rb', line 25 def collection @_collection ||= open['events'] end |
#ensure_indexes ⇒ Object
29 30 31 |
# File 'lib/mongo_entity_store/external_store.rb', line 29 def ensure_indexes collection.ensure_index([['_type', Mongo::ASCENDING], ['_id', Mongo::ASCENDING]]) end |
#get_events(since, type = nil, max_items = 100) ⇒ Object
Public - get events since a Time or ID
since - Time or String id to filter events from type - String optionally filter the event type to return (default=nil) max_items - Fixnum max items to return (default=100)
Returns Enumerable EventDataObject
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongo_entity_store/external_store.rb', line 47 def get_events(since, type=nil, max_items=100) since_id = since.is_a?(Time) ? BSON::ObjectId.from_time(since) : BSON::ObjectId.from_string(since) query = { '_id' => { '$gt' => since_id } } query['_type'] = type if type = { :sort => [['_id', Mongo::ASCENDING]], :limit => max_items } collection.find(query, ).collect { |e| EventDataObject.new(e)} end |
#open ⇒ Object
21 22 23 |
# File 'lib/mongo_entity_store/external_store.rb', line 21 def open ExternalStore.connection.db(ExternalStore.database) end |