Class: RubyEventStore::Mappers::Transformation::Encryption

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/mappers/transformation/encryption.rb

Defined Under Namespace

Classes: MissingEncryptionKey

Instance Method Summary collapse

Constructor Details

#initialize(key_repository, serializer: Serializers::YAML, forgotten_data: ForgottenData.new) ⇒ Encryption

Returns a new instance of Encryption.



20
21
22
23
24
# File 'lib/ruby_event_store/mappers/transformation/encryption.rb', line 20

def initialize(key_repository, serializer: Serializers::YAML, forgotten_data: ForgottenData.new)
  @key_repository = key_repository
  @serializer = serializer
  @forgotten_data = forgotten_data
end

Instance Method Details

#dump(record) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_event_store/mappers/transformation/encryption.rb', line 26

def dump(record)
  data = record.data
   = record..dup
  event_class = Object.const_get(record.event_type)

  crypto_description = (data, encryption_schema(event_class))
  [:encryption] = crypto_description unless crypto_description.empty?

  Record.new(
    event_id: record.event_id,
    event_type: record.event_type,
    data: encrypt_data(deep_dup(data), crypto_description),
    metadata: ,
    timestamp: record.timestamp,
    valid_at: record.valid_at
  )
end

#load(record) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby_event_store/mappers/transformation/encryption.rb', line 44

def load(record)
   = record..dup
  crypto_description = Hash(.delete(:encryption))

  Record.new(
    event_id: record.event_id,
    event_type: record.event_type,
    data: decrypt_data(record.data, crypto_description),
    metadata: ,
    timestamp: record.timestamp,
    valid_at: record.valid_at
  )
end