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.
8 9 10 11 |
# File 'lib/spikard/service.rb', line 8 def initialize # Create a new application with the default server configuration. @registrations = [] end |
Instance Method Details
#config(config) ⇒ Object
12 13 14 15 16 |
# File 'lib/spikard/service.rb', line 12 def config(config) # Set the server configuration. @config = config self end |
#connect(path: String, &block) ⇒ Object
66 67 68 69 70 |
# File 'lib/spikard/service.rb', line 66 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
51 52 53 54 55 |
# File 'lib/spikard/service.rb', line 51 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
31 32 33 34 35 |
# File 'lib/spikard/service.rb', line 31 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
56 57 58 59 60 |
# File 'lib/spikard/service.rb', line 56 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
84 85 86 87 88 89 90 91 |
# File 'lib/spikard/service.rb', line 84 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
61 62 63 64 65 |
# File 'lib/spikard/service.rb', line 61 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
46 47 48 49 50 |
# File 'lib/spikard/service.rb', line 46 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
36 37 38 39 40 |
# File 'lib/spikard/service.rb', line 36 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
41 42 43 44 45 |
# File 'lib/spikard/service.rb', line 41 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
26 27 28 29 30 |
# File 'lib/spikard/service.rb', line 26 def register_route(builder, handler) # Register a route callback directly without block syntax. @registrations.push(["route", [builder], handler]) self end |
#route(builder, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/spikard/service.rb', line 17 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
76 77 78 79 80 81 82 83 |
# File 'lib/spikard/service.rb', line 76 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
71 72 73 74 75 |
# File 'lib/spikard/service.rb', line 71 def trace(path: String, &block) # Register a TRACE route at the given path. @registrations.push(["trace", [spikard::Method::Trace, path], block]) self end |