Class: Hyphy::Sampler

Inherits:
Object
  • Object
show all
Defined in:
lib/hyphy/sampler.rb

Defined Under Namespace

Classes: UnsupportedORMException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Sampler

Returns a new instance of Sampler.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hyphy/sampler.rb', line 7

def initialize(opts={})
  orm = opts[:orm] || :active_record

  if orm == :active_record
    @orm_adapter = Hyphy::ActiveRecordAdapter
  else
    raise UnsupportedORMException, 'ORM #{orm} is not supported'
  end

   = {}
end

Instance Attribute Details

#metadata_callbacksObject (readonly)

Returns the value of attribute metadata_callbacks.



3
4
5
# File 'lib/hyphy/sampler.rb', line 3

def 
  
end

#orm_adapterObject (readonly)

Returns the value of attribute orm_adapter.



3
4
5
# File 'lib/hyphy/sampler.rb', line 3

def orm_adapter
  @orm_adapter
end

Instance Method Details

#add_metadata(name, &block) ⇒ Object



37
38
39
# File 'lib/hyphy/sampler.rb', line 37

def (name, &block)
  [name] = block
end

#beginObject



41
42
43
# File 'lib/hyphy/sampler.rb', line 41

def begin
  @orm_adapter.subscribe_to_sql_notifications(method(:sample))
end

#log_sql(statement, start_time, end_time) ⇒ Object



19
20
21
22
23
24
# File 'lib/hyphy/sampler.rb', line 19

def log_sql(statement, start_time, end_time)
  Hyphy::SQLStatement.create(:statement => statement,
                             :start_time => start_time,
                             :end_time => end_time,
                             :trace_json => JSON(caller))
end

#process_metadata(sql_statement) ⇒ Object



26
27
28
29
30
# File 'lib/hyphy/sampler.rb', line 26

def (sql_statement)
  .each do |key, value_block|
    sql_statement.(key, value_block.call)
  end
end

#sample(statement, start_time, end_time) ⇒ Object



32
33
34
35
# File 'lib/hyphy/sampler.rb', line 32

def sample(statement, start_time, end_time)
  sql_statement = log_sql(statement, start_time, end_time)
  (sql_statement)
end