Class: Temporalio::SearchAttributes::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/search_attributes.rb

Overview

Key for a search attribute.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Key

Returns a new instance of Key.

Raises:

  • (ArgumentError)


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

#nameString (readonly)

Returns Name of the search attribute.

Returns:

  • (String)

    Name of the search attribute.



15
16
17
# File 'lib/temporalio/search_attributes.rb', line 15

def name
  @name
end

#typeIndexedValueType (readonly)

Returns Type of the search attribute.

Returns:



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.

Returns:

  • (Boolean)

    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

#hashInteger

Returns Hash.

Returns:

  • (Integer)

    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.

Raises:

  • (TypeError)

    The value does not have the proper 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

#value_set(value) ⇒ Update

Create an updated that sets the given value for this key.

Parameters:

  • value (Object)

    Value to update. Must be the proper type for the key.

Returns:

  • (Update)

    Created update.

Raises:

  • (ArgumentError)


74
75
76
77
78
# File 'lib/temporalio/search_attributes.rb', line 74

def value_set(value)
  raise ArgumentError, 'Value cannot be nil, use value_unset' if value.nil?

  Update.new(self, value)
end

#value_unsetUpdate

Create an updated that unsets the key.

Returns:

  • (Update)

    Created update.



83
84
85
# File 'lib/temporalio/search_attributes.rb', line 83

def value_unset
  Update.new(self, nil)
end