Module: CLIHelpers
Overview
CLI for this gem
Constant Summary collapse
- LOGGER =
LoggingFactory::DEFAULT_FACTORY.log('MockServerClient')
Constants included from MockServer
MockServer::CLEAR_ENDPOINT, MockServer::DUMP_LOG_ENDPOINT, MockServer::EXPECTATION_ENDPOINT, MockServer::HTTP_FORWARD, MockServer::HTTP_REQUEST, MockServer::HTTP_RESPONSE, MockServer::HTTP_TIMES, MockServer::RESET_ENDPOINT, MockServer::RETRIEVE_ENDPOINT, MockServer::VERSION
Instance Method Summary collapse
-
#error(message) ⇒ Object
Prints an error message.
-
#execute_command(mockserver = false, data_required = false, error_msg = '--data option must be provided') {|a, a| ... } ⇒ Object
Process a block using options extracted into a struct.
-
#mockserver_client(options) ⇒ MockServerClient
Create a mockserver client.
-
#print_parameters(options) ⇒ Object
Prints out the parameters passed to it.
-
#proxy_client(options) ⇒ ProxyClient
Create a proxy client.
-
#read_file(file) ⇒ Object
Read a file.
-
#to_struct(hash) ⇒ Struct
Convert a hash to a struct.
Instance Method Details
#error(message) ⇒ Object
Prints an error message
65 66 67 |
# File 'lib/cli.rb', line 65 def error() puts .red end |
#execute_command(mockserver = false, data_required = false, error_msg = '--data option must be provided') {|a, a| ... } ⇒ Object
Process a block using options extracted into a struct
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cli.rb', line 52 def execute_command(mockserver = false, data_required = false, error_msg = '--data option must be provided', &_) print_parameters() = to_struct({ data: nil }.merge()) if data_required && !['data'] error(error_msg) else client = mockserver ? mockserver_client() : proxy_client() yield client, if block_given? end end |
#mockserver_client(options) ⇒ MockServerClient
Create a mockserver client
25 26 27 28 29 |
# File 'lib/cli.rb', line 25 def mockserver_client() client = MockServerClient.new(.host, .port) client.logger = LOGGER client end |
#print_parameters(options) ⇒ Object
Prints out the parameters passed to it
16 17 18 19 20 |
# File 'lib/cli.rb', line 16 def print_parameters() puts "\nRunning with parameters:".bold .each { |k, v| puts "\t#{k}: #{v}".yellow } puts '' end |
#proxy_client(options) ⇒ ProxyClient
Create a proxy client
34 35 36 37 38 |
# File 'lib/cli.rb', line 34 def proxy_client() client = ProxyClient.new(.host, .port) client.logger = LOGGER client end |
#read_file(file) ⇒ Object
Read a file
71 72 73 |
# File 'lib/cli.rb', line 71 def read_file(file) YAML.load_file(file) end |
#to_struct(hash) ⇒ Struct
Convert a hash to a struct
43 44 45 46 |
# File 'lib/cli.rb', line 43 def to_struct(hash) hash = symbolize_keys(hash) Struct.new(*hash.keys).new(*hash.values) end |