Module: Eipiai::Representable
- Included in:
- Api
- Defined in:
- lib/eipiai/models/representable.rb
Overview
Representable
Module used to make a model “representable”.
When including this module into a class, it is expected that a similar class with a suffix “Representer” exists.
Instance Method Summary collapse
-
#from_hash(hash = {}) ⇒ Object
from_hash.
-
#path ⇒ String
path.
-
#represented ⇒ Object
represented.
-
#to_h(options = {}) ⇒ Hash
to_h.
Instance Method Details
#from_hash(hash = {}) ⇒ Object
from_hash
call ‘#from_hash` on the representer belonging to the object.
51 52 53 |
# File 'lib/eipiai/models/representable.rb', line 51 def from_hash(hash = {}) represented.from_hash(hash) end |
#path ⇒ String
path
The “path” to access the model. This method calls the representer’s ‘path` method.
66 67 68 |
# File 'lib/eipiai/models/representable.rb', line 66 def path represented.path end |
#represented ⇒ Object
represented
Return the represented version of the object.
21 22 23 |
# File 'lib/eipiai/models/representable.rb', line 21 def represented "#{self.class.name}Representer".constantize.new(self) end |
#to_h(options = {}) ⇒ Hash
to_h
call ‘#to_h` on the representer belonging to the object.
36 37 38 |
# File 'lib/eipiai/models/representable.rb', line 36 def to_h( = {}) represented.to_h() end |