Class: AI::Items
- Inherits:
-
Object
- Object
- AI::Items
- Defined in:
- lib/ai/items.rb
Overview
NOTE: This is intentionally not a SimpleDelegator.
IRB’s default inspector uses PP, and PP has special handling for Delegator instances that unwraps them (via __getobj__) before printing. That causes IRB to display the underlying OpenAI cursor page instead of our custom formatted output.
By using a plain wrapper + method_missing delegation, ‘chat.get_items` displays nicely in IRB/Rails console while still forwarding API helpers like `.data`, `.has_more`, etc.
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(response, conversation_id:) ⇒ Items
constructor
A new instance of Items.
- #inspect ⇒ Object
- #method_missing(method_name, *args, &block) ⇒ Object
- #pretty_inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #to_html ⇒ Object
Constructor Details
#initialize(response, conversation_id:) ⇒ Items
Returns a new instance of Items.
15 16 17 18 |
# File 'lib/ai/items.rb', line 15 def initialize(response, conversation_id:) @response = response @conversation_id = conversation_id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
42 43 44 45 46 |
# File 'lib/ai/items.rb', line 42 def method_missing(method_name, *args, &block) return super unless response.respond_to?(method_name) response.public_send(method_name, *args, &block) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
20 21 22 |
# File 'lib/ai/items.rb', line 20 def response @response end |
Instance Method Details
#data ⇒ Object
22 23 24 |
# File 'lib/ai/items.rb', line 22 def data response.data end |
#inspect ⇒ Object
30 31 32 |
# File 'lib/ai/items.rb', line 30 def inspect build_output(html: false, plain: !$stdout.tty?) end |
#pretty_inspect ⇒ Object
34 35 36 |
# File 'lib/ai/items.rb', line 34 def pretty_inspect "#{inspect}\n" end |
#pretty_print(q) ⇒ Object
38 39 40 |
# File 'lib/ai/items.rb', line 38 def pretty_print(q) q.output << inspect end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
48 49 50 |
# File 'lib/ai/items.rb', line 48 def respond_to_missing?(method_name, include_private = false) response.respond_to?(method_name, include_private) || super end |