Class: Riffer::Tools::Param Private
- Inherits:
-
Object
- Object
- Riffer::Tools::Param
- Defined in:
- lib/riffer/tools/param.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Riffer::Tools::Param represents a single parameter definition for a tool.
Handles type validation and JSON Schema generation for individual parameters.
Constant Summary collapse
- TYPE_MAPPINGS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps Ruby types to JSON Schema type strings
{ String => "string", Integer => "integer", Float => "number", TrueClass => "boolean", FalseClass => "boolean", Array => "array", Hash => "object" }.freeze
Instance Attribute Summary collapse
- #default ⇒ Object readonly private
- #description ⇒ Object readonly private
- #enum ⇒ Object readonly private
- #name ⇒ Object readonly private
- #required ⇒ Object readonly private
- #type ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(name:, type:, required:, description: nil, enum: nil, default: nil) ⇒ Param
constructor
private
Creates a new parameter definition.
-
#to_json_schema ⇒ Hash
private
Converts this parameter to JSON Schema format.
-
#type_name ⇒ String
private
Returns the JSON Schema type name for this parameter.
-
#valid_type?(value) ⇒ Boolean
private
Validates that a value matches the expected type.
Constructor Details
#initialize(name:, type:, required:, description: nil, enum: nil, default: nil) ⇒ Param
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new parameter definition
29 30 31 32 33 34 35 36 |
# File 'lib/riffer/tools/param.rb', line 29 def initialize(name:, type:, required:, description: nil, enum: nil, default: nil) @name = name.to_sym @type = type @required = required @description = description @enum = enum @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def default @default end |
#description ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def description @description end |
#enum ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def enum @enum end |
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def name @name end |
#required ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def required @required end |
#type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/riffer/tools/param.rb', line 20 def type @type end |
Instance Method Details
#to_json_schema ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts this parameter to JSON Schema format
59 60 61 62 63 64 |
# File 'lib/riffer/tools/param.rb', line 59 def to_json_schema schema = {type: type_name} schema[:description] = description if description schema[:enum] = enum if enum schema end |
#type_name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the JSON Schema type name for this parameter
53 54 55 |
# File 'lib/riffer/tools/param.rb', line 53 def type_name TYPE_MAPPINGS[type] || type.to_s.downcase end |
#valid_type?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates that a value matches the expected type
41 42 43 44 45 46 47 48 49 |
# File 'lib/riffer/tools/param.rb', line 41 def valid_type?(value) return true if value.nil? && !required if type == TrueClass || type == FalseClass value == true || value == false else value.is_a?(type) end end |