Class: Temporalio::SearchAttributes::Key
- Inherits:
-
Object
- Object
- Temporalio::SearchAttributes::Key
- Defined in:
- lib/temporalio/search_attributes.rb
Overview
Key for a search attribute.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Name of the search attribute.
-
#type ⇒ IndexedValueType
readonly
Type of the search attribute.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Check equality.
-
#hash ⇒ Integer
Hash.
-
#initialize(name, type) ⇒ Key
constructor
A new instance of Key.
-
#validate_value(value) ⇒ Object
Validate that the given value matches the expected #type.
-
#value_set(value) ⇒ Update
Create an updated that sets the given value for this key.
-
#value_unset ⇒ Update
Create an updated that unsets the key.
Constructor Details
#initialize(name, type) ⇒ Key
Returns a new instance of Key.
20 21 22 23 24 25 |
# File 'lib/temporalio/search_attributes.rb', line 20 def initialize(name, type) raise ArgumentError, 'Invalid type' unless Api::Enums::V1::IndexedValueType.lookup(type) @name = name @type = type end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns Name of the search attribute.
15 16 17 |
# File 'lib/temporalio/search_attributes.rb', line 15 def name @name end |
#type ⇒ IndexedValueType (readonly)
Returns Type of the search attribute.
18 19 20 |
# File 'lib/temporalio/search_attributes.rb', line 18 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns Check equality.
28 29 30 |
# File 'lib/temporalio/search_attributes.rb', line 28 def ==(other) other.is_a?(Key) && other.name == @name && other.type == @type end |
#hash ⇒ Integer
Returns Hash.
35 36 37 |
# File 'lib/temporalio/search_attributes.rb', line 35 def hash [self.class, @name, @age].hash end |
#validate_value(value) ⇒ Object
Validate that the given value matches the expected #type.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/temporalio/search_attributes.rb', line 42 def validate_value(value) case type when IndexedValueType::TEXT raise TypeError, 'Value of TEXT key must be a String' unless value.is_a?(String) when IndexedValueType::KEYWORD raise TypeError, 'Value of KEYWORD key must be a String' unless value.is_a?(String) when IndexedValueType::INTEGER raise TypeError, 'Value of INTEGER key must be a Integer' unless value.is_a?(Integer) when IndexedValueType::FLOAT unless value.is_a?(Float) || value.is_a?(Integer) raise TypeError, 'Value of FLOAT key must be a Float or Integer' end when IndexedValueType::BOOLEAN unless value.is_a?(TrueClass) || value.is_a?(FalseClass) raise TypeError, 'Value of BOOLEAN key must be a Boolean' end when IndexedValueType::TIME raise TypeError, 'Value of TIME key must be a Time' unless value.is_a?(Time) when IndexedValueType::KEYWORD_LIST unless value.is_a?(Array) && value.all? { |v| v.is_a?(String) } raise TypeError, 'Value of KEYWORD_LIST key must be an Array of String' end else # Should never happen, checked in constructor raise 'Unrecognized key type' end end |