Class: Relay::Forms::MCP
- Inherits:
-
Object
- Object
- Relay::Forms::MCP
- Defined in:
- app/forms/mcp.rb,
app/forms/mcp/github.rb,
app/forms/mcp/forgejo.rb
Overview
The MCP class represents preset-backed MCP form state. It holds the shared persisted fields for Relay’s MCP UI and dispatches to preset-specific subclasses for GitHub and Forgejo.
Defined Under Namespace
Instance Attribute Summary collapse
-
#id ⇒ Integer, ...
readonly
Returns the MCP row id when editing an existing server.
Class Method Summary collapse
-
.build(preset:, attributes: {}) ⇒ Relay::Forms::MCP
A preset-specific form instance.
-
.from_model(mcp) ⇒ Relay::Forms::MCP
A preset-specific form instance.
-
.from_params(params) ⇒ Relay::Forms::MCP
A preset-specific form instance.
Instance Method Summary collapse
-
#initialize(id: nil, persisted: false) ⇒ MCP
constructor
A new instance of MCP.
-
#persisted? ⇒ Boolean
Returns true when this form was built from a persisted MCP row.
Constructor Details
#initialize(id: nil, persisted: false) ⇒ MCP
Returns a new instance of MCP.
77 78 79 80 |
# File 'app/forms/mcp.rb', line 77 def initialize(id: nil, persisted: false) @id = id @persisted = persisted end |
Instance Attribute Details
#id ⇒ Integer, ... (readonly)
Returns the MCP row id when editing an existing server
12 13 14 |
# File 'app/forms/mcp.rb', line 12 def id @id end |
Class Method Details
.build(preset:, attributes: {}) ⇒ Relay::Forms::MCP
Returns A preset-specific form instance.
64 65 66 67 68 69 70 |
# File 'app/forms/mcp.rb', line 64 def self.build(preset:, attributes: {}) case preset when "forgejo" then Forgejo.new(**attributes) when "github" then GitHub.new(**attributes) else raise ArgumentError, "Unknown MCP preset: #{preset.inspect}" end end |
.from_model(mcp) ⇒ Relay::Forms::MCP
Returns A preset-specific form instance.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/forms/mcp.rb', line 19 def self.from_model(mcp) common = { id: mcp.id, persisted: true } case preset = mcp.data["preset"] when "forgejo" attributes = common.merge(url: mcp.env["FORGEJO_URL"], token: mcp.env["FORGEJO_TOKEN"]) build(preset:, attributes:) when "github" attributes = common.merge(token: mcp.headers["Authorization"].to_s.delete_prefix("Bearer ").strip) build(preset:, attributes:) else raise ArgumentError, "Unknown MCP preset: #{mcp.data["preset"].inspect}" end end |
.from_params(params) ⇒ Relay::Forms::MCP
Returns A preset-specific form instance.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/forms/mcp.rb', line 41 def self.from_params(params) common = { id: params["id"], persisted: false } case preset = params["preset"] when "forgejo" attributes = common.merge(url: params["url"], token: params["token"]) build(preset:, attributes:) when "github" build(preset:, attributes: common.merge(token: params["token"])) else raise ArgumentError, "Unknown MCP preset: #{params["preset"].inspect}" end end |
Instance Method Details
#persisted? ⇒ Boolean
Returns true when this form was built from a persisted MCP row
85 86 87 |
# File 'app/forms/mcp.rb', line 85 def persisted? @persisted end |