Class: FauxLambda::CliHandler
- Inherits:
-
Object
- Object
- FauxLambda::CliHandler
- Defined in:
- lib/faux_lambda/cli_handler.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #handler(call) ⇒ Object
-
#initialize ⇒ CliHandler
constructor
A new instance of CliHandler.
- #parse_options(argv) ⇒ Object
Constructor Details
#initialize ⇒ CliHandler
Returns a new instance of CliHandler.
6 7 8 9 10 11 12 13 14 |
# File 'lib/faux_lambda/cli_handler.rb', line 6 def initialize @functions = { default: { invocation_type: nil, replies: [] } } = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/faux_lambda/cli_handler.rb', line 4 def end |
Instance Method Details
#handler(call) ⇒ Object
48 49 50 51 |
# File 'lib/faux_lambda/cli_handler.rb', line 48 def handler(call) data = function_data(call) reply_from(data[:replies], call) end |
#parse_options(argv) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/faux_lambda/cli_handler.rb', line 16 def (argv) current_function = :default parser = OptionParser.new do |opts| opts. = "AWS Lambda debugging endpoint, version #{FauxLambda::VERSION}." opts.separator('') opts.separator('Usage: faux-lambda --reply "Hello world!"') opts.separator('Query specifiers:') opts.on('--function name', '-f name', 'Name of function to expect, optionally with :<qualifier>') do |function_name| current_function = function_name @functions[current_function] = {replies: []} end opts.separator('Reply specifiers:') opts.on('--reply payload', '-r payload', 'Data to respond with') do |payload| @functions[current_function][:replies] << lambda {|_| payload } end opts.on('--handler script.rb', '-h script.rb', 'Ruby script is eval:ed to produce reply') do |script| @functions[current_function][:replies] << make_handler(script) end opts.on('--fail', 'AWS Lambda framework gives 400') do @functions[current_function][:replies] << lambda {|_| :fail } end opts.separator('Control options') opts.on('--port port', 'TCP port to bind, 9123 by default') do |port| [:port] = port end opts.on('--bind address', 'Interface to bind to, localhost by default') do |bindaddress| [:bind] = bindaddress end end parser.parse!(argv) end |