Class: PromptObjects::Service
- Inherits:
-
Object
- Object
- PromptObjects::Service
- Defined in:
- lib/prompt_objects/service.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#delete_env_data(key) ⇒ Boolean
Delete an env_data entry.
-
#get_env_data(key) ⇒ Object?
Read a value from shared env_data.
-
#initialize(runtime:) ⇒ Service
constructor
A new instance of Service.
-
#interval ⇒ Object
Seconds between ticks.
-
#list_env_data ⇒ Array<Hash>
List env_data keys and descriptions in the active environment session.
-
#set_env_data(key, value, short_description: nil) ⇒ Boolean
Store a value in shared env_data, scoped to the active environment session.
-
#start ⇒ Object
Called when the server starts.
-
#stop ⇒ Object
Called when the server stops.
-
#tick ⇒ Object
Called every
intervalseconds.
Constructor Details
#initialize(runtime:) ⇒ Service
Returns a new instance of Service.
29 30 31 32 33 34 35 36 |
# File 'lib/prompt_objects/service.rb', line 29 def initialize(runtime:) @runtime = runtime @name = self.class.name.split("::").last .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase @description = nil end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
27 28 29 |
# File 'lib/prompt_objects/service.rb', line 27 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/prompt_objects/service.rb', line 27 def name @name end |
Instance Method Details
#delete_env_data(key) ⇒ Boolean
Delete an env_data entry.
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/prompt_objects/service.rb', line 104 def delete_env_data(key) scope = env_data_scope return false unless scope deleted = @runtime.session_store.delete_env_data(root_thread_id: scope, key: key) if deleted @runtime.notify_env_data_changed( action: "delete", root_thread_id: scope, key: key, stored_by: "service:#{name}" ) end deleted end |
#get_env_data(key) ⇒ Object?
Read a value from shared env_data.
84 85 86 87 88 89 90 |
# File 'lib/prompt_objects/service.rb', line 84 def get_env_data(key) scope = env_data_scope return nil unless scope entry = @runtime.session_store.get_env_data(root_thread_id: scope, key: key) entry && entry[:value] end |
#interval ⇒ Object
Seconds between ticks. Return nil to disable auto-tick.
45 |
# File 'lib/prompt_objects/service.rb', line 45 def interval; nil; end |
#list_env_data ⇒ Array<Hash>
List env_data keys and descriptions in the active environment session.
94 95 96 97 98 99 |
# File 'lib/prompt_objects/service.rb', line 94 def list_env_data scope = env_data_scope return [] unless scope @runtime.session_store.list_env_data(root_thread_id: scope) end |
#set_env_data(key, value, short_description: nil) ⇒ Boolean
Store a value in shared env_data, scoped to the active environment session. Creates the environment session on first write if one doesn't exist yet.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prompt_objects/service.rb', line 64 def set_env_data(key, value, short_description: nil) scope = env_data_scope(create: true) return false unless scope @runtime.session_store.store_env_data( root_thread_id: scope, key: key, short_description: short_description || key.to_s, value: value, stored_by: "service:#{name}" ) @runtime.notify_env_data_changed( action: "set", root_thread_id: scope, key: key, stored_by: "service:#{name}" ) true end |
#start ⇒ Object
Called when the server starts. Override to initialize resources.
39 |
# File 'lib/prompt_objects/service.rb', line 39 def start; end |
#stop ⇒ Object
Called when the server stops. Override to clean up resources.
42 |
# File 'lib/prompt_objects/service.rb', line 42 def stop; end |
#tick ⇒ Object
Called every interval seconds. Override to perform periodic work.
48 |
# File 'lib/prompt_objects/service.rb', line 48 def tick; end |