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
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
76 77 78 79 80 |
# File 'lib/spikard/service.rb', line 76 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
58 59 60 61 62 |
# File 'lib/spikard/service.rb', line 58 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
34 35 36 37 38 |
# File 'lib/spikard/service.rb', line 34 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
64 65 66 67 68 |
# File 'lib/spikard/service.rb', line 64 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
97 98 99 100 101 102 103 104 |
# File 'lib/spikard/service.rb', line 97 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
70 71 72 73 74 |
# File 'lib/spikard/service.rb', line 70 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
52 53 54 55 56 |
# File 'lib/spikard/service.rb', line 52 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
40 41 42 43 44 |
# File 'lib/spikard/service.rb', line 40 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
46 47 48 49 50 |
# File 'lib/spikard/service.rb', line 46 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
28 29 30 31 32 |
# File 'lib/spikard/service.rb', line 28 def register_route(builder, handler) # Register a route callback directly without block syntax. @registrations.push(["route", [builder], handler]) self end |
#route(builder, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/spikard/service.rb', line 18 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
88 89 90 91 92 93 94 95 |
# File 'lib/spikard/service.rb', line 88 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
82 83 84 85 86 |
# File 'lib/spikard/service.rb', line 82 def trace(path: String, &block) # Register a TRACE route at the given path. @registrations.push(["trace", [spikard::Method::Trace, path], block]) self end |