Class: Tidewave::Tools::GetModels
- Inherits:
-
Tidewave::Tool
- Object
- Tidewave::Tool
- Tidewave::Tools::GetModels
- Defined in:
- lib/tidewave/tools/get_models.rb
Constant Summary collapse
- DESCRIPTION =
<<~DESCRIPTION.freeze Returns a list of all database-backed models in the application. DESCRIPTION
Instance Method Summary collapse
- #call(_arguments) ⇒ Object
- #definition ⇒ Object
-
#initialize(options = {}) ⇒ GetModels
constructor
A new instance of GetModels.
Methods inherited from Tidewave::Tool
descendants, inherited, #validate_and_call
Constructor Details
#initialize(options = {}) ⇒ GetModels
Returns a new instance of GetModels.
10 11 12 13 14 |
# File 'lib/tidewave/tools/get_models.rb', line 10 def initialize( = {}) @root = [:root] ? Pathname.new([:root].to_s) : Pathname.pwd @database_adapter = Tidewave::DatabaseAdapter.for([:orm_adapter]) if [:orm_adapter] @before_reload = [:before_reload] end |
Instance Method Details
#call(_arguments) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tidewave/tools/get_models.rb', line 29 def call(_arguments) @before_reload&.call models = @database_adapter.get_models models.map do |model| display_name = model.name || model.to_s if location = get_relative_source_location(model.name) "* #{display_name} at #{location}" else "* #{display_name}" end end.join("\n") end |
#definition ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tidewave/tools/get_models.rb', line 16 def definition return nil unless @database_adapter { "name" => "get_models", "description" => DESCRIPTION, "inputSchema" => { "type" => "object", "properties" => {} } } end |