Class: OmnifocusMcp::Tools::Operations::ListPerspectives
- Inherits:
-
Object
- Object
- OmnifocusMcp::Tools::Operations::ListPerspectives
- Defined in:
- lib/omnifocus_mcp/tools/operations/list_perspectives.rb
Class Method Summary collapse
- .call(params = nil, script_runner: Infrastructure::ScriptRunner, **kwargs) ⇒ Object
- .classify_response(response:, include_built_in:, include_custom:) ⇒ Object
- .filter_perspectives(perspectives:, include_built_in:, include_custom:) ⇒ Object
Instance Method Summary collapse
- #call(params = {}) ⇒ Object
- #classify_response(response:, include_built_in:, include_custom:) ⇒ Object
- #filter_perspectives(perspectives:, include_built_in:, include_custom:) ⇒ Object
-
#initialize(script_runner: Infrastructure::ScriptRunner, generator: Generators::ListPerspectives) ⇒ ListPerspectives
constructor
A new instance of ListPerspectives.
Constructor Details
#initialize(script_runner: Infrastructure::ScriptRunner, generator: Generators::ListPerspectives) ⇒ ListPerspectives
Returns a new instance of ListPerspectives.
35 36 37 38 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 35 def initialize(script_runner: Infrastructure::ScriptRunner, generator: Generators::ListPerspectives) @script_runner = script_runner @generator = generator end |
Class Method Details
.call(params = nil, script_runner: Infrastructure::ScriptRunner, **kwargs) ⇒ Object
13 14 15 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 13 def call(params = nil, script_runner: Infrastructure::ScriptRunner, **kwargs) merge_params(params, kwargs).then { |params| new(script_runner:).call(params) } end |
.classify_response(response:, include_built_in:, include_custom:) ⇒ Object
17 18 19 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 17 def classify_response(response:, include_built_in:, include_custom:) new.classify_response(response:, include_built_in:, include_custom:) end |
.filter_perspectives(perspectives:, include_built_in:, include_custom:) ⇒ Object
21 22 23 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 21 def filter_perspectives(perspectives:, include_built_in:, include_custom:) new.filter_perspectives(perspectives:, include_built_in:, include_custom:) end |
Instance Method Details
#call(params = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 40 def call(params = {}) params = Params::McpBoundary.coerce(Params::ListPerspectivesParams, params) script_runner.execute_omnifocus_script(generator.script_path) .and_then do |response| classify_response( response:, include_built_in: params.include_built_in, include_custom: params.include_custom ) end rescue StandardError => e OmnifocusMcp.logger.warn("[list_perspectives] Error: #{e}") OmnifocusMcp::Result.error(e. || "Unknown error occurred") end |
#classify_response(response:, include_built_in:, include_custom:) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 56 def classify_response(response:, include_built_in:, include_custom:) shape = response.is_a?(Hash) ? response.transform_keys(&:to_sym) : nil case shape in { error: String => msg } OmnifocusMcp::Result.error(msg) in { perspectives: Array => perspectives } OmnifocusMcp::Result.ok( filter_perspectives(perspectives:, include_built_in:, include_custom:) ) in Hash OmnifocusMcp::Result.ok([]) in nil OmnifocusMcp::Result.error("Unexpected response from listPerspectives.js: #{response.inspect}") end end |
#filter_perspectives(perspectives:, include_built_in:, include_custom:) ⇒ Object
73 74 75 76 77 |
# File 'lib/omnifocus_mcp/tools/operations/list_perspectives.rb', line 73 def filter_perspectives(perspectives:, include_built_in:, include_custom:) perspectives = perspectives.reject { |perspective| perspective["type"] == "builtin" } unless include_built_in perspectives = perspectives.reject { |perspective| perspective["type"] == "custom" } unless include_custom perspectives end |