Module: A2A::Extensions::AdditionalProperties

Included in:
AuthenticationInfo
Defined in:
lib/a2a/extensions/additional_properties.rb

Overview

Allows a dry-struct to have additional properties beyond the defined schema. Limitations: the attributes method does not return additional properties.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object?

Access additional properties via method_missing

Parameters:

  • method_name (Symbol)

    Method name corresponding to property

  • args (Array)

    Method arguments (unused)

Returns:

  • (Object, nil)

    Property value if found



30
31
32
33
34
35
36
# File 'lib/a2a/extensions/additional_properties.rb', line 30

def method_missing(method_name, *args)
  if additional_properties.key?(method_name)
    additional_properties[method_name]
  else
    super
  end
end

Instance Method Details

#camelize(value) ⇒ Object

Override the camelize method to handle additional properties correctly

Parameters:

  • value (Object)

    The value to convert

Returns:

  • (Object)

    The value with camelized keys if applicable



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/a2a/extensions/additional_properties.rb', line 63

def camelize(value)
  case value
  when Hash
    value.to_h do |key, v|
      [INFLECTOR.camelize_lower(key.to_s).to_sym, camelize(v)]
    end
  when Array
    value.map { |item| camelize(item) }
  else
    value
  end
end

#initializeObject

Initialize with empty additional properties



18
19
20
21
# File 'lib/a2a/extensions/additional_properties.rb', line 18

def initialize(*)
  super
  @additional_properties ||= {}
end

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

Indicate whether the object responds to the given method

Parameters:

  • method_name (Symbol)

    Method name

  • include_private (Boolean) (defaults to: false)

    Whether to include private methods

Returns:

  • (Boolean)

    Whether the object responds to the method



45
46
47
# File 'lib/a2a/extensions/additional_properties.rb', line 45

def respond_to_missing?(method_name, include_private = false)
  additional_properties.key?(method_name) || super
end

#to_hHash

Convert the struct to a hash, including additional properties

Returns:

  • (Hash)

    All properties as a hash



53
54
55
# File 'lib/a2a/extensions/additional_properties.rb', line 53

def to_h
  super.merge(additional_properties)
end