Module: Victor::Marshaling

Included in:
Component, SVGBase
Defined in:
lib/victor/marshaling.rb

Instance Method Summary collapse

Instance Method Details

#encode_with(coder) ⇒ Object

YAML serialization methods



8
9
10
11
12
# File 'lib/victor/marshaling.rb', line 8

def encode_with(coder)
  marshaling.each do |attr|
    coder[attr.to_s] = send(attr)
  end
end

#init_with(coder) ⇒ Object



14
15
16
17
18
# File 'lib/victor/marshaling.rb', line 14

def init_with(coder)
  marshaling.each do |attr|
    instance_variable_set(:"@#{attr}", coder[attr.to_s])
  end
end

#marshal_dumpObject

Marshal serialization methods



21
22
23
24
25
# File 'lib/victor/marshaling.rb', line 21

def marshal_dump
  marshaling.to_h do |attr|
    [attr, send(attr)]
  end
end

#marshal_load(data) ⇒ Object



27
28
29
30
31
# File 'lib/victor/marshaling.rb', line 27

def marshal_load(data)
  marshaling.each do |attr|
    instance_variable_set(:"@#{attr}", data[attr])
  end
end

#marshalingObject

Raises:

  • (NotImplementedError)


3
4
5
# File 'lib/victor/marshaling.rb', line 3

def marshaling
  raise NotImplementedError, "#{self.class.name} must implement `marshaling'"
end