Module: Prmd::CLI::Stub

Extended by:
Base
Defined in:
lib/prmd/cli/stub.rb

Overview

‘stub’ command module’

Class Method Summary collapse

Methods included from Base

execute, make_parser, noop_execute, parse_options, run

Class Method Details

.execute(options = {}) ⇒ void

This method returns an undefined value.

Executes the ‘stub’ command.

Examples:

Usage

Prmd::CLI::Stub.execute(argv: ['schema/api.json'])

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prmd/cli/stub.rb', line 28

def self.execute(options = {})
  require "committee"

  filename = options.fetch(:argv).first
  _, schema = try_read(filename)

  app = Rack::Builder.new {
    use Committee::Middleware::RequestValidation, schema: schema
    use Committee::Middleware::ResponseValidation, schema: schema
    use Committee::Middleware::Stub, schema: schema
    run lambda { |_| [404, {}, ["Not found"]] }
  }

  Rack::Server.start(app: app)
end

.make_parser(options = {}) ⇒ OptionParser

Returns a OptionParser for parsing ‘stub’ command options.

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})

Returns:



13
14
15
16
17
18
19
# File 'lib/prmd/cli/stub.rb', line 13

def self.make_parser(options = {})
  binname = options.fetch(:bin, 'prmd')

  OptionParser.new do |opts|
    opts.banner = "#{binname} stub [options] <combined schema>"
  end
end