Class: DataStore::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/data_store/connector.rb

Instance Method Summary collapse

Instance Method Details

#create_table!Object

Create the data_stores table with the following attributes

  • primary_key :id

  • Integer :identifier, unique: true, null: false

  • String :name, null: false

  • String :type, null: false

  • String :description

  • DateTime :created_at

  • DateTime :updated_at



15
16
17
18
19
# File 'lib/data_store/connector.rb', line 15

def create_table!
  DataStore.create_data_stores.apply(database, :up)
rescue Sequel::DatabaseError => e
  raise e if e.message.include?('FATAL')
end

#databaseObject

Return the database object to which its connected.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/data_store/connector.rb', line 37

def database
  @database ||= begin
    if ENV['DATABASE_URL']
      Sequel.connect(ENV['DATABASE_URL'])
    elsif RUBY_PLATFORM == 'java'
      Sequel.connect(jdbc_settings)
    else
      Sequel.connect(database_settings)
    end
  end
end

#datasetObject

Return the dataset associated with data_stores



29
30
31
32
33
34
# File 'lib/data_store/connector.rb', line 29

def dataset
  @dataset ||= begin
    create_table!
    database[:data_stores]
  end
end

#reset!Object

Drop data_stores table and recreate it



22
23
24
25
26
# File 'lib/data_store/connector.rb', line 22

def reset!
  drop_table!
  create_table!
  disconnect
end