Class: RailsApiBenchmark::Endpoint
- Inherits:
-
Object
- Object
- RailsApiBenchmark::Endpoint
- Includes:
- Logging
- Defined in:
- lib/rails_api_benchmark/endpoint.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #benchmark ⇒ Object
-
#initialize(opts) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #query ⇒ Object
- #run_benchmark ⇒ Object
Methods included from Logging
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
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/rails_api_benchmark/endpoint.rb', line 9 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/rails_api_benchmark/endpoint.rb', line 9 def name @name end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
9 10 11 |
# File 'lib/rails_api_benchmark/endpoint.rb', line 9 def route @route end |
#title ⇒ Object (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
#benchmark ⇒ Object
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 |
#query ⇒ Object
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_benchmark ⇒ Object
20 21 22 23 24 |
# File 'lib/rails_api_benchmark/endpoint.rb', line 20 def run_benchmark query benchmark @results end |