Class: MetricSystem::Web

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/metric_system/web.rb

Class Method Summary collapse

Class Method Details

.connectionObject

return a database for the current thread



21
22
23
# File 'lib/metric_system/web.rb', line 21

def self.connection
  Thread.current[:"MetricSystem::Web.database"] ||= MetricSystem::Database.new(self.database, :readonly)
end

.register_query(name, query) ⇒ Object



12
13
14
# File 'lib/metric_system/web.rb', line 12

def self.register_query(name, query)
  registry[name] = query
end

.registryObject



16
17
18
# File 'lib/metric_system/web.rb', line 16

def self.registry
  @registry ||= {}
end

.select(query, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/metric_system/web.rb', line 25

def self.select(query, *args)
  expect! query => [ String, Symbol ]

  if query.is_a?(Symbol)
    expect! query => registry.keys
    query = registry.fetch(query)
  end

  result = connection.select query, *args #period: "month"
  result.data_table.to_js
end