Module: Chassis::Serializable
- Defined in:
- lib/chassis/serializable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #from_hash(hash) ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
- #to_json ⇒ Object
- #to_yaml ⇒ Object
Class Method Details
.included(base) ⇒ Object
21 22 23 |
# File 'lib/chassis/serializable.rb', line 21 def included(base) base.extend ClassMethods end |
Instance Method Details
#from_hash(hash) ⇒ Object
47 48 49 50 |
# File 'lib/chassis/serializable.rb', line 47 def from_hash(hash) marshal_load HashUtils.symbolize(hash) self end |
#marshal_dump ⇒ Object
26 27 28 |
# File 'lib/chassis/serializable.rb', line 26 def marshal_dump fail NotImplementedError, 'subclass must implement marshal_dump' end |
#marshal_load(hash) ⇒ Object
30 31 32 |
# File 'lib/chassis/serializable.rb', line 30 def marshal_load(hash) fail NotImplementedError, 'subclass must implement marshal_load' end |
#to_hash ⇒ Object Also known as: to_h
34 35 36 |
# File 'lib/chassis/serializable.rb', line 34 def to_hash marshal_dump end |
#to_json ⇒ Object
39 40 41 |
# File 'lib/chassis/serializable.rb', line 39 def to_json JSON.dump marshal_dump end |
#to_yaml ⇒ Object
43 44 45 |
# File 'lib/chassis/serializable.rb', line 43 def to_yaml YAML.dump marshal_dump end |