Class: TacScribe::Datastore
- Inherits:
-
Object
- Object
- TacScribe::Datastore
- Includes:
- GeoRuby::SimpleFeatures, Singleton
- Defined in:
- lib/tac_scribe/datastore.rb
Overview
Acts as the interface to the back-end datastore and hides all datastore implementation details from callers. Note that ruby does not support exception chaining we are not wrapping exceptions yet. This will happen when bugs.ruby-lang.org/issues/8257 is fixed.
Defined Under Namespace
Classes: Configuration
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
Instance Method Summary collapse
- #configuration ⇒ Object
- #configure {|@configuration| ... } ⇒ Object
- #connect ⇒ Object
- #delete_object(object_id) ⇒ Object
- #truncate_table ⇒ Object
- #write_object(event, timestamp) ⇒ Object
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
17 18 19 |
# File 'lib/tac_scribe/datastore.rb', line 17 def db @db end |
Instance Method Details
#configuration ⇒ Object
22 23 24 |
# File 'lib/tac_scribe/datastore.rb', line 22 def configuration @configuration ||= Configuration.new end |
#configure {|@configuration| ... } ⇒ Object
26 27 28 29 |
# File 'lib/tac_scribe/datastore.rb', line 26 def configure configuration yield(@configuration) if block_given? end |
#connect ⇒ Object
45 46 47 48 49 |
# File 'lib/tac_scribe/datastore.rb', line 45 def connect configure @db = Sequel.connect(connection_string, max_connections: 49) @db.extension :postgis_georuby end |
#delete_object(object_id) ⇒ Object
70 71 72 73 |
# File 'lib/tac_scribe/datastore.rb', line 70 def delete_object(object_id) count = @db[:units].where(id: object_id).delete "Deleted #{object_id} #{object_id.class} - #{count}" end |
#truncate_table ⇒ Object
51 52 53 |
# File 'lib/tac_scribe/datastore.rb', line 51 def truncate_table @db[:units].truncate end |
#write_object(event, timestamp) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tac_scribe/datastore.rb', line 55 def write_object(event, ) unit = get_unit(event[:object_id]) # Tacview omits values that don't change to save # data bandwidth and storage. If something has not changed then # use the old value current_position = get_position(event, unit) if unit update_unit(event, unit, current_position, ) else insert_unit(event, current_position, ) end end |