Class: Webhookdb::TypedStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/webhookdb/typed_struct.rb

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ TypedStruct

Returns a new instance of TypedStruct.



4
5
6
# File 'lib/webhookdb/typed_struct.rb', line 4

def initialize(**kwargs)
  self._apply(self._defaults.merge(kwargs))
end

Instance Method Details

#[](k) ⇒ Object



12
13
14
# File 'lib/webhookdb/typed_struct.rb', line 12

def [](k)
  return self.send(k)
end

#_apply(kwargs) ⇒ Object

Modify the receiver with kwargs.



17
18
19
20
21
22
# File 'lib/webhookdb/typed_struct.rb', line 17

def _apply(kwargs)
  kwargs.each do |k, v|
    raise TypeError, "invalid struct field #{k}" unless self.respond_to?(k)
    self.instance_variable_set(:"@#{k}", v)
  end
end

#_defaultsObject



8
9
10
# File 'lib/webhookdb/typed_struct.rb', line 8

def _defaults
  return {}
end

#as_jsonObject



30
31
32
# File 'lib/webhookdb/typed_struct.rb', line 30

def as_json
  return self.instance_values.as_json
end

#changeObject



24
25
26
27
28
# File 'lib/webhookdb/typed_struct.rb', line 24

def change(**)
  c = self.dup
  c._apply(**)
  return c
end