Class: Rambo::RSpec::HelperFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rambo/rspec/helper_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path:, file_path:, raml: nil, options: nil) ⇒ HelperFile

Returns a new instance of HelperFile.



11
12
13
14
15
16
# 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 || { rails: true }
  @raml          = raml ? Rambo::RamlModels::Api.new(raml) : nil
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/rambo/rspec/helper_file.rb', line 9

def options
  @options
end

Instance Method Details

#generateObject



18
19
20
# File 'lib/rambo/rspec/helper_file.rb', line 18

def generate
  write_to_file(render) unless file_already_exists?
end

#renderObject



22
23
24
25
26
# File 'lib/rambo/rspec/helper_file.rb', line 22

def render
  b = binding
  ERB.new(template, 0, "-", "@result").result(raml.instance_eval { b })
  @result
end