Class: ApiSketch::Runner

Inherits:
Object
  • Object
show all
Includes:
Mixlib::CLI
Defined in:
lib/api_sketch/runner.rb

Instance Method Summary collapse

Instance Method Details

#runObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/api_sketch/runner.rb', line 64

def run
  parse_options

  if config[:generate] || config[:examples_server]
    raise ApiSketch::Error, "Definitions parameter should be a directory" unless File.directory?(config[:definitions_dir])
    config[:project_name] = File.basename(config[:definitions_dir]).gsub("_", " ").gsub(/\w+/, &:capitalize) if (config[:project_name].nil? || config[:project_name].empty?)
  end

  ::ApiSketch::Config.merge!(config)

  if config[:generate]
    ApiSketch::Generators::Bootstrap.new(config).generate!
  end

  if config[:examples_server]
    ::ApiSketch::Model::Resource.reload!(config[:definitions_dir])

    builder = Rack::Builder.new do
      use ::Rack::PostBodyContentTypeParser
      use ::Rack::NestedParams
      run ::ApiSketch::ExamplesServer
    end

    Rack::Handler::WEBrick.run builder, :Port => config[:examples_server_port]
  end
end