Module: Sinatra::XRPCRoutes
- Defined in:
- lib/xrpc/server.rb
Instance Method Summary collapse
Instance Method Details
#xrpc_get(lexicon, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/xrpc/server.rb', line 5 def xrpc_get(lexicon, &block) # Extract the parameter names from the block's parameters parameters = block.parameters.map { |type, name| name.to_s } # Define a new route with the provided lexicon and block get "/xrpc/#{lexicon}" do content_type :json # Create a hash of arguments with parameter names as keys args = {} parameters.each do |param| args[param] = params[param] if params[param] end # Call the block with the arguments instance_exec(args, &block) end end |
#xrpc_post(lexicon, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xrpc/server.rb', line 23 def xrpc_post(lexicon, &block) # Extract the parameter names from the block's parameters parameters = block.parameters.map { |type, name| name.to_s } # Define a new route with the provided lexicon and block post "/xrpc/#{lexicon}" do content_type :json # Create a hash of arguments with parameter names as keys args = {} parameters.each do |param| args[param] = params[param] if params[param] end # Call the block with the arguments instance_exec(args, &block) end end |