Class: BlockKit::Types::Set

Inherits:
Array
  • Object
show all
Defined in:
lib/block_kit/types/set.rb

Overview

Allows declaring ActiveModel attributes that are Sets of specific types, powered by an internal TypedSet class that enforces type constraints on set members any time the set is modified or any time set operations are performed against other collections.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#initialize, of

Constructor Details

This class inherits a constructor from BlockKit::Types::Array

Instance Attribute Details

#item_typeObject (readonly)

Returns the value of attribute item_type.



12
13
14
# File 'lib/block_kit/types/set.rb', line 12

def item_type
  @item_type
end

Instance Method Details

#cast(value) ⇒ Object



18
19
20
21
22
# File 'lib/block_kit/types/set.rb', line 18

def cast(value)
  return nil if value.nil?

  TypedSet.new(item_type, Array(value))
end

#changed_in_place?(raw_old_value, new_value) ⇒ Boolean



30
31
32
# File 'lib/block_kit/types/set.rb', line 30

def changed_in_place?(raw_old_value, new_value)
  cast(raw_old_value) != cast(new_value)
end

#serialize(value) ⇒ Object



24
25
26
27
28
# File 'lib/block_kit/types/set.rb', line 24

def serialize(value)
  return nil if value.nil?

  cast(value)
end

#typeObject



14
15
16
# File 'lib/block_kit/types/set.rb', line 14

def type
  :set
end