Class: AgentClientProtocol::TaggedUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_client_protocol/helpers.rb

Overview

A session update tagged with its discriminator value. Serializes to include the "sessionUpdate" key in the wire format.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, model) ⇒ TaggedUpdate

Returns a new instance of TaggedUpdate.



145
146
147
148
# File 'lib/agent_client_protocol/helpers.rb', line 145

def initialize(tag, model)
  @tag = tag
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



164
165
166
167
168
169
170
# File 'lib/agent_client_protocol/helpers.rb', line 164

def method_missing(method, ...)
  if @model.respond_to?(method)
    @model.send(method, ...)
  else
    super
  end
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



143
144
145
# File 'lib/agent_client_protocol/helpers.rb', line 143

def model
  @model
end

#tagObject (readonly)

Returns the value of attribute tag.



143
144
145
# File 'lib/agent_client_protocol/helpers.rb', line 143

def tag
  @tag
end

Instance Method Details

#inspectObject



172
173
174
# File 'lib/agent_client_protocol/helpers.rb', line 172

def inspect
  "#<TaggedUpdate tag=#{@tag.inspect} #{@model.inspect}>"
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Delegate attribute access to the underlying model

Returns:

  • (Boolean)


160
161
162
# File 'lib/agent_client_protocol/helpers.rb', line 160

def respond_to_missing?(method, include_private = false)
  @model.respond_to?(method, include_private) || super
end

#to_hObject



150
151
152
153
# File 'lib/agent_client_protocol/helpers.rb', line 150

def to_h
  h = @model.is_a?(Schema::BaseModel) ? @model.to_h : @model
  {"sessionUpdate" => @tag}.merge(h)
end

#to_jsonObject



155
156
157
# File 'lib/agent_client_protocol/helpers.rb', line 155

def to_json(*)
  JSON.generate(to_h, *)
end