class Rambo::RSpec::HelperFile

Attributes

file_path[R]
options[R]
raml[R]
template_path[R]

Public Class Methods

new(template_path:, file_path:, raml: nil, options: nil) click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 11
def initialize(template_path:, file_path:, raml: nil, options: nil)
  @template_path = template_path
  @file_path     = file_path
  @options       = options || { framework: :rails }
  @raml          = raml ? Rambo::RamlModels::Api.new(raml) : nil
end

Public Instance Methods

app_classes() click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 18
def app_classes
  {
    :rails             => "Rails.application",
    :"sinatra:classic" => "Sinatra::Application",
    :"sinatra:modular" => "Sinatra::Base.descendants.find {|klass| klass != Sinatra::Application } || Sinatra::Application",
    :grape             => "Grape::API.descendants.first",
    :rory              => "Rory.application"
  }
end
generate() click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 28
def generate
  write_to_file(render) unless file_already_exists?
end
render() click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 32
def render
  b = binding
  ERB.new(template, 0, "-", "@result").result(raml.instance_eval { b })
  @result
end

Private Instance Methods

file_already_exists?() click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 42
def file_already_exists?
  File.exist?(file_path)
end
template() click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 50
def template
  @template ||= File.read(template_path)
end
write_to_file(template) click to toggle source
# File lib/rambo/rspec/helper_file.rb, line 46
def write_to_file(template)
  File.write(file_path, template)
end