Class: JSInstrument::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/jsinstrument/instrumenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#batch_textObject

Returns the value of attribute batch_text.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def batch_text
  @batch_text
end

#commit_hashObject

Returns the value of attribute commit_hash.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def commit_hash
  @commit_hash
end

#data_compress_methodObject

Returns the value of attribute data_compress_method.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def data_compress_method
  @data_compress_method
end

#js_object_nameObject

Returns the value of attribute js_object_name.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def js_object_name
  @js_object_name
end

#project_nameObject

Returns the value of attribute project_name.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def project_name
  @project_name
end

#src_filenameObject

Returns the value of attribute src_filename.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def src_filename
  @src_filename
end

#upload_urlObject

Returns the value of attribute upload_url.



10
11
12
# File 'lib/jsinstrument/instrumenter.rb', line 10

def upload_url
  @upload_url
end

Instance Method Details

#instrument(src, filename) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jsinstrument/instrumenter.rb', line 20

def instrument src, filename
  raise 'Filename not set' unless filename
  self.src_filename = filename
  ast = RKelly::Parser.new.parse src
  raise 'Parse source failed.' unless ast
  ast, instrumented_lines = instrument_ast ast
  instrumented_src = ast.to_ecma

  inserting = File.open(File.dirname(__FILE__) + '/inserting.js').read

  bindings = {
    js_object_name: self.js_object_name,
    upload_url: self.upload_url,
    src_filename: self.src_filename,
    project_name: self.project_name,
    commit_hash: self.commit_hash,
    batch_text: self.batch_text,
    data_compress_method: self.data_compress_method,
    instrumented_lines: instrumented_lines
  }

  (inserting % bindings) + instrumented_src
end