Module: Victor::Marshaling
Instance Method Summary collapse
-
#encode_with(coder) ⇒ Object
YAML serialization methods.
- #init_with(coder) ⇒ Object
-
#marshal_dump ⇒ Object
Marshal serialization methods.
- #marshal_load(data) ⇒ Object
- #marshaling ⇒ Object
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_dump ⇒ Object
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 |
#marshaling ⇒ Object
3 4 5 |
# File 'lib/victor/marshaling.rb', line 3 def marshaling raise NotImplementedError, "#{self.class.name} must implement `marshaling'" end |