class RailsApiBenchmark::Views::View

Public Class Methods

new(*_args) click to toggle source
# File lib/rails_api_benchmark/views/view.rb, line 6
def initialize(*_args)
  @config = RailsApiBenchmark.config
  @template_path = File.expand_path('../templates', __dir__)
end

Public Instance Methods

file_name() click to toggle source

Override this method in your view

# File lib/rails_api_benchmark/views/view.rb, line 12
def file_name
  "#{@file_name}.#{extension}"
end
file_path() click to toggle source
# File lib/rails_api_benchmark/views/view.rb, line 21
def file_path
  [folder, file_name].compact.join('/')
end
folder() click to toggle source

Override this method in your view

# File lib/rails_api_benchmark/views/view.rb, line 17
def folder
  nil
end
render() click to toggle source
# File lib/rails_api_benchmark/views/view.rb, line 31
def render
  template = File.read(File.join(@template_path, "#{template_name}.erb"))
  Erubis::Eruby.new(template).result(binding)
end
write() click to toggle source
# File lib/rails_api_benchmark/views/view.rb, line 25
def write
  File.open(File.join(@config.results_folder, file_path), 'w') do |file|
    file << render
  end
end

Private Instance Methods

template_name() click to toggle source
# File lib/rails_api_benchmark/views/view.rb, line 38
def template_name # Avoid module
  self.class.name
      .split('::').last
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .downcase
end