Module: DataStore

Defined in:
lib/data_store.rb,
lib/data_store/base.rb,
lib/data_store/table.rb,
lib/data_store/version.rb,
lib/data_store/connector.rb,
lib/data_store/definitions.rb,
lib/data_store/configuration.rb,
lib/data_store/average_calculator.rb

Defined Under Namespace

Classes: AverageCalculator, Base, Configuration, Connector, Table

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.configurationObject

The configuration object. See Configuration



54
55
56
# File 'lib/data_store.rb', line 54

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Configure DataStore

Example

DataStore.configure |config|
  config.prefix   = 'data_store_'
  config.database = :postgres
end

Yields:



48
49
50
51
# File 'lib/data_store.rb', line 48

def configure
  yield(configuration)
  define_base_class
end

.create_data_storesObject

Definition of the data_stores table



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/data_store/definitions.rb', line 4

def self.create_data_stores
  Sequel.migration do
    change do
      create_table(:data_stores) do
        primary_key :id
        Integer     :identifier, unique: true, null: false
        String      :name, null: false
        String      :type, null: false
        String      :description
        String      :data_type
        String      :compression_schema
        Integer     :frequency
        Integer     :maximum_datapoints
        DateTime    :created_at
        DateTime    :updated_at
        index       :identifier
      end
    end
  end
end

.create_table(settings) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/data_store/definitions.rb', line 25

def self.create_table(settings)
  name           = settings[:name]
  original_value = settings[:original_value] || false
  data_type      = settings[:data_type]

  Sequel.migration do
    change do
      create_table(name) do
        primary_key :id
        column :value, data_type
        column :original_value, data_type if original_value
        column :created, :double
        index  :created
      end
    end
  end
end