Class: Matt::Exporter::Sql

Inherits:
Object
  • Object
show all
Includes:
Matt::Exporter
Defined in:
lib/matt/exporter/sql.rb

Instance Attribute Summary collapse

Attributes included from Support::Participant

#configuration, #name

Instance Method Summary collapse

Methods included from Support::Participant

#class_name, #fail!, #to_s

Methods included from Support::Puts

#debug, #info, #puts_err, #puts_out, #stderr, #stdout

Constructor Details

#initialize(arg) ⇒ Sql

Returns a new instance of Sql.



6
7
8
9
10
11
12
13
14
15
# File 'lib/matt/exporter/sql.rb', line 6

def initialize(arg)
  case @config = arg
  when String
  when Hash
  when Sequel::Database
  when Matt::Datasource::Sql
  else
    raise ArgumentError, "Unable to use `#{arg}` to create an Sql exporter"
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/matt/exporter/sql.rb', line 16

def config
  @config
end

Instance Method Details

#export(measure, data) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/matt/exporter/sql.rb', line 26

def export(measure, data)
  now = Time.now
  data = data.constants(:created_at => now)
  table = ensure_table!(measure)
  remove_old_data!(table, data)
  insert_new_data!(table, data)
end

#sequel_dbObject



18
19
20
21
22
23
24
# File 'lib/matt/exporter/sql.rb', line 18

def sequel_db
  @sequel_db ||= case config
  when Sequel::Database      then config
  when Matt::Datasource::Sql then config.sequel_db
  else Sequel.connect(config)
  end
end