tool_tailor 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 840fcc0f9e8a7f5ccd4db0d8f4a8d88f2f344225d8f759442dc11f625d243300
4
- data.tar.gz: 53289290ee809ea4e18acf08de8115d4c259b337823fd9ad506de6c335eb12db
3
+ metadata.gz: 908a6461c07d131d14e6bd8be1a3fa6fa578e4f0261110d084238dbc657e8f33
4
+ data.tar.gz: 65541821e6c287d82e1bffd57e04da0c541654ea3e8edc84621cc0fbfbe11604
5
5
  SHA512:
6
- metadata.gz: 682eea6fb802c1a1444cafbe077577594cd682c7e02071313b56c7e737c738575b82098cbc6a4a63287edf449a0cd0aed9c4dcb225386350e4b2653270dac585
7
- data.tar.gz: 8606a2abd5309a6ab9f7d7fdfa1910c953d674708aa9dce5c2e9fee29168f979632b3f4b8567dd2c5aba68d6fdfc18a2aebc000f464d63f20cc005c7c0452925
6
+ metadata.gz: 798fb99b7ac1fba192eec08684ac51d1f39f11e7bb6ff79757987a2aaabba1bb749ed865278dc37639e08ef6cd04b11de68f461ebbb0ee09433db3cb3d090f97
7
+ data.tar.gz: 4a2aeda57a2757776a05845d29fb1a09c479d2352820d5be0930c6b7b75c01c59f4712cd9367cda3e758e5c1d3c6d00385080b1768be256a1fde20ea73eb871d
data/README.md CHANGED
@@ -29,21 +29,22 @@ class WeatherService
29
29
  # Get the current weather in a given location.
30
30
  #
31
31
  # @param location [String] The city and state, e.g., San Francisco, CA.
32
- # @param unit [String] The unit of temperature, either 'celsius' or 'fahrenheit'.
33
- def get_current_weather(location:, unit: 'celsius')
32
+ # @param unit [String] The temperature unit to use. Infer this from the user's location.
33
+ # @values unit ["Celsius", "Fahrenheit"]
34
+ def get_current_temperature(location:, unit:)
34
35
  # Function implementation goes here
35
36
  end
36
37
  end
37
38
 
38
39
  # Convert an instance method
39
- schema = ToolTailor.convert(WeatherService.instance_method(:get_current_weather))
40
+ schema = ToolTailor.convert(WeatherService.instance_method(:get_current_temperature))
40
41
 
41
42
  # Using to_json_schema on an unbound method
42
- schema = WeatherService.instance_method(:get_current_weather).to_json_schema
43
+ schema = WeatherService.instance_method(:get_current_temperature).to_json_schema
43
44
 
44
45
  # Using to_json_schema on a bound method
45
46
  weather_service = WeatherService.new
46
- schema = weather_service.method(:get_current_weather).to_json_schema
47
+ schema = weather_service.method(:get_current_temperature).to_json_schema
47
48
  ```
48
49
 
49
50
  ### Converting Classes
@@ -1,3 +1,3 @@
1
1
  module ToolTailor
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/tool_tailor.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "tool_tailor/version"
2
2
  require "json"
3
3
  require "yard"
4
+ require "yard_custom_tags"
4
5
 
5
6
  module ToolTailor
6
7
  class Error < StandardError; end
@@ -58,7 +59,8 @@ module ToolTailor
58
59
  {
59
60
  name: name.to_s,
60
61
  type: "string",
61
- description: ""
62
+ description: "",
63
+ enum: nil
62
64
  }
63
65
  end
64
66
 
@@ -75,6 +77,12 @@ module ToolTailor
75
77
  param[:description] = tag.text
76
78
  end
77
79
  end
80
+
81
+ yard_object.tags("values").each do |tag|
82
+ param_name = tag.name.chomp(':')
83
+ param = parameters.find { |p| p[:name] == param_name }
84
+ param[:enum] = tag.text if param
85
+ end
78
86
  end
79
87
 
80
88
  {
@@ -89,8 +97,9 @@ module ToolTailor
89
97
  param[:name],
90
98
  {
91
99
  type: param[:type],
92
- description: param[:description]
93
- }
100
+ description: param[:description],
101
+ enum: param[:enum]
102
+ }.compact
94
103
  ]
95
104
  end.to_h,
96
105
  required: method.parameters.select { |type, _| type == :keyreq }.map { |_, name| name.to_s }
@@ -0,0 +1,46 @@
1
+ require "yard"
2
+
3
+ module YARD
4
+ module Tags
5
+ # Custom tag class for handling `@values` tags.
6
+ class ValuesTag < YARD::Tags::Tag
7
+ TAG_FORMAT = /^(\S+)\s+\[(.+)\]$/
8
+
9
+ def initialize(tag_name, text)
10
+ name, values = parse_text(text)
11
+ super(tag_name, values, nil, name)
12
+ end
13
+
14
+ private
15
+
16
+ # Parses the text to match the expected format and extract the name and values.
17
+ def parse_text(text)
18
+ match = text.match(TAG_FORMAT)
19
+ unless match
20
+ raise ArgumentError, "Invalid @values tag format. Expected: @values <name> [value1, value2, ...]. Values should be a JSON array."
21
+ end
22
+
23
+ name, values_text = match.captures
24
+ values = parse_values(values_text)
25
+ [name, values]
26
+ end
27
+
28
+ # Parses the values text as a JSON array to ensure correct types.
29
+ def parse_values(values_text)
30
+ json_text = "[#{values_text}]"
31
+ JSON.parse(json_text)
32
+ rescue JSON::ParserError => e
33
+ raise ArgumentError, "Invalid values format: #{e.message}"
34
+ end
35
+ end
36
+
37
+ class Library
38
+ def self.define_custom_tag
39
+ # Defines a new custom tag `@values` using the ValuesTag class.
40
+ YARD::Tags::Library.define_tag("Values", :values, ValuesTag)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ YARD::Tags::Library.define_custom_tag
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tool_tailor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Klaassen
@@ -45,6 +45,7 @@ files:
45
45
  - bin/setup
46
46
  - lib/tool_tailor.rb
47
47
  - lib/tool_tailor/version.rb
48
+ - lib/yard_custom_tags.rb
48
49
  - tool_tailor.gemspec
49
50
  homepage: https://github.com/kieranklaassen/tool_tailor
50
51
  licenses: