Class: Rambo::DocumentGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/document_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ DocumentGenerator



11
12
13
14
15
# File 'lib/document_generator.rb', line 11

def initialize(file, options={})
  @file    = file
  @raml    = Raml::Parser.parse_file(file)
  @options = options
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#ramlObject

Returns the value of attribute raml.



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

def raml
  @raml
end

Instance Method Details

#generate_examples!Object



21
22
23
# File 'lib/document_generator.rb', line 21

def generate_examples!
  FileUtils.mkdir_p("spec/support/examples")
end

#generate_matcher_dir!Object



38
39
40
# File 'lib/document_generator.rb', line 38

def generate_matcher_dir!
  FileUtils.mkdir_p("spec/support/matchers")
end

#generate_matchers!Object



42
43
44
45
46
47
# File 'lib/document_generator.rb', line 42

def generate_matchers!
  Rambo::RSpec::HelperFile.new(
    template_path: File.expand_path("../rspec/templates/matcher_file_template.erb", __FILE__),
    file_path: "spec/support/matchers/rambo_matchers.rb"
  ).generate
end

#generate_rambo_helper!Object



31
32
33
34
35
36
# File 'lib/document_generator.rb', line 31

def generate_rambo_helper!
  Rambo::RSpec::HelperFile.new(
    template_path: File.expand_path("../rspec/templates/rambo_helper_file_template.erb", __FILE__),
    file_path: "spec/rambo_helper.rb"
  ).generate
end

#generate_spec_dir!Object



17
18
19
# File 'lib/document_generator.rb', line 17

def generate_spec_dir!
  FileUtils.mkdir_p("spec/contract/output")
end

#generate_spec_file!Object



25
26
27
28
29
# File 'lib/document_generator.rb', line 25

def generate_spec_file!
  spec_file_name = file.match(/[^\/]*\.raml$/).to_s.gsub(/\.raml$/, "_spec.rb")
  contents       = Rambo::RSpec::SpecFile.new(raml, options).render
  File.write("spec/contract/#{spec_file_name}", contents)
end