Class: Committee::Bin::CommitteeStub
- Inherits:
-
Object
- Object
- Committee::Bin::CommitteeStub
- Defined in:
- lib/committee/bin/committee_stub.rb
Overview
CommitteeStub internalizes the functionality of bin/committee-stub so that we can test code that would otherwise be difficult to get at in an executable.
Instance Method Summary collapse
-
#get_app(schema, options) ⇒ Object
Gets a Rack app suitable for use as a stub.
-
#get_options_parser ⇒ Object
Gets an option parser for command line arguments.
Instance Method Details
#get_app(schema, options) ⇒ Object
Gets a Rack app suitable for use as a stub.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/committee/bin/committee_stub.rb', line 12 def get_app(schema, ) cache = {} raise Committee::OpenAPI3Unsupported.new("Stubs are not yet supported for OpenAPI 3") unless schema.supports_stub? Rack::Builder.new { unless [:tolerant] use Committee::Middleware::RequestValidation, schema: schema use Committee::Middleware::ResponseValidation, schema: schema end use Committee::Middleware::Stub, cache: cache, schema: schema run lambda { |_| [404, {}, ["Not found"]] } } end |
#get_options_parser ⇒ Object
Gets an option parser for command line arguments.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/committee/bin/committee_stub.rb', line 32 def = { driver: nil, help: false, port: 9292, tolerant: false, } parser = OptionParser.new do |opts| opts. = "Usage: rackup [options] [JSON Schema file]" opts.separator "" opts.separator "Options:" # required opts.on("-d", "--driver NAME", "name of driver [open_api_2|hyper_schema]") { |name| [:driver] = name.to_sym } opts.on_tail("-h", "-?", "--help", "Show this message") { [:help] = true } opts.on("-t", "--tolerant", "don't perform request/response validations") { [:tolerant] = true } opts.on("-p", "--port PORT", "use PORT (default: 9292)") { |port| [:port] = port } end [, parser] end |