Module: Chassis::Serializable

Defined in:
lib/chassis/serializable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

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_dumpObject



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_hashObject Also known as: to_h



34
35
36
# File 'lib/chassis/serializable.rb', line 34

def to_hash
  marshal_dump
end

#to_jsonObject



39
40
41
# File 'lib/chassis/serializable.rb', line 39

def to_json
  JSON.dump marshal_dump
end

#to_yamlObject



43
44
45
# File 'lib/chassis/serializable.rb', line 43

def to_yaml
  YAML.dump marshal_dump
end