Class: Spikard::App
- Inherits:
-
Object
- Object
- Spikard::App
- Defined in:
- lib/spikard/service.rb
Overview
Spikard application builder.
Instance Method Summary collapse
- #config(config) ⇒ Object
- #connect(path: String, &block) ⇒ Object
- #delete(path: String, &block) ⇒ Object
- #get(path: String, &block) ⇒ Object
- #head(path: String, &block) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #into_router ⇒ Object
- #options(path: String, &block) ⇒ Object
- #patch(path: String, &block) ⇒ Object
- #post(path: String, &block) ⇒ Object
- #put(path: String, &block) ⇒ Object
- #register_route(builder, handler) ⇒ Object
- #route(builder, &block) ⇒ Object
- #run ⇒ Object
- #trace(path: String, &block) ⇒ Object
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
7 8 9 10 |
# File 'lib/spikard/service.rb', line 7 def initialize # Create a new application with the default server configuration. @registrations = [] end |
Instance Method Details
#config(config) ⇒ Object
11 12 13 14 15 |
# File 'lib/spikard/service.rb', line 11 def config(config) # Set the server configuration. @config = config self end |
#connect(path: String, &block) ⇒ Object
65 66 67 68 69 |
# File 'lib/spikard/service.rb', line 65 def connect(path: String, &block) # Register a CONNECT route at the given path. @registrations.push(["connect", [spikard::Method::Connect, path], block]) self end |
#delete(path: String, &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/spikard/service.rb', line 50 def delete(path: String, &block) # Register a DELETE route at the given path. @registrations.push(["delete", [spikard::Method::Delete, path], block]) self end |
#get(path: String, &block) ⇒ Object
30 31 32 33 34 |
# File 'lib/spikard/service.rb', line 30 def get(path: String, &block) # Register a GET route at the given path. @registrations.push(["get", [spikard::Method::Get, path], block]) self end |
#head(path: String, &block) ⇒ Object
55 56 57 58 59 |
# File 'lib/spikard/service.rb', line 55 def head(path: String, &block) # Register a HEAD route at the given path. @registrations.push(["head", [spikard::Method::Head, path], block]) self end |
#into_router ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/spikard/service.rb', line 83 def into_router # Build the underlying Axum router. # # # Errors # # Returns an error if server or router construction fails. Spikard.app_into_router(@registrations) end |
#options(path: String, &block) ⇒ Object
60 61 62 63 64 |
# File 'lib/spikard/service.rb', line 60 def (path: String, &block) # Register an OPTIONS route at the given path. @registrations.push(["options", [spikard::Method::Options, path], block]) self end |
#patch(path: String, &block) ⇒ Object
45 46 47 48 49 |
# File 'lib/spikard/service.rb', line 45 def patch(path: String, &block) # Register a PATCH route at the given path. @registrations.push(["patch", [spikard::Method::Patch, path], block]) self end |
#post(path: String, &block) ⇒ Object
35 36 37 38 39 |
# File 'lib/spikard/service.rb', line 35 def post(path: String, &block) # Register a POST route at the given path. @registrations.push(["post", [spikard::Method::Post, path], block]) self end |
#put(path: String, &block) ⇒ Object
40 41 42 43 44 |
# File 'lib/spikard/service.rb', line 40 def put(path: String, &block) # Register a PUT route at the given path. @registrations.push(["put", [spikard::Method::Put, path], block]) self end |
#register_route(builder, handler) ⇒ Object
25 26 27 28 29 |
# File 'lib/spikard/service.rb', line 25 def register_route(builder, handler) # Register a route callback directly without block syntax. @registrations.push(["route", [builder], handler]) self end |
#route(builder, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/spikard/service.rb', line 16 def route(builder, &block) # Register a route using the provided builder and handler function. # # # Errors # # Returns an error if route construction fails or if the handler registration fails. @registrations.push(["route", [builder], block]) self end |
#run ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/spikard/service.rb', line 75 def run # Run the HTTP server using the configured routes. # # # Errors # # Returns an error if server construction or execution fails. Spikard.app_run(@registrations) end |
#trace(path: String, &block) ⇒ Object
70 71 72 73 74 |
# File 'lib/spikard/service.rb', line 70 def trace(path: String, &block) # Register a TRACE route at the given path. @registrations.push(["trace", [spikard::Method::Trace, path], block]) self end |