Class: RailsApiBenchmark::Endpoint

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/rails_api_benchmark/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #logger

Constructor Details

#initialize(opts) ⇒ Endpoint

Returns a new instance of Endpoint.



11
12
13
14
15
16
17
18
# File 'lib/rails_api_benchmark/endpoint.rb', line 11

def initialize(opts)
  @name = opts[:name]
  @route = opts[:route]
  @method = opts[:method]
  @title = opts[:title]
  @results = {}
  @results_folder = "#{RailsApiBenchmark.config.results_folder}/#{@name}"
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/rails_api_benchmark/endpoint.rb', line 9

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/rails_api_benchmark/endpoint.rb', line 9

def name
  @name
end

#routeObject (readonly)

Returns the value of attribute route.



9
10
11
# File 'lib/rails_api_benchmark/endpoint.rb', line 9

def route
  @route
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/rails_api_benchmark/endpoint.rb', line 9

def title
  @title
end

Instance Method Details

#benchmarkObject



26
27
28
29
30
31
32
33
34
# File 'lib/rails_api_benchmark/endpoint.rb', line 26

def benchmark
  benchmark_cmd = RailsApiBenchmark.config.bench_cmd
  opts = RailsApiBenchmark.config.all.merge(route: @route)

  output = `#{benchmark_cmd % opts}`

  regexps = RailsApiBenchmark.config.regexps
  regexps.each { |r| @results[r[:key]] = output.scan(r[:regexp]).flatten.first }
end

#queryObject



36
37
38
39
40
41
# File 'lib/rails_api_benchmark/endpoint.rb', line 36

def query
  curl_cmd = RailsApiBenchmark.config.curl_cmd
  opts = RailsApiBenchmark.config.all.merge(route: @route)

  @results[:response] = JSON.pretty_generate(JSON.parse(`#{curl_cmd % opts}`))
end

#run_benchmarkObject



20
21
22
23
24
# File 'lib/rails_api_benchmark/endpoint.rb', line 20

def run_benchmark
  query
  benchmark
  @results
end