Module: Eipiai::Representer
- Included in:
- ApiRepresenter
- Defined in:
- lib/eipiai/roar/representers/base.rb
Overview
Representer
The base Representer which all representers should include.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#path ⇒ String
path.
-
#url(uri = nil) ⇒ String
url.
Class Method Details
.included(base) ⇒ Object
12 13 14 15 |
# File 'lib/eipiai/roar/representers/base.rb', line 12 def self.included(base) base.include(Roar::JSON::HAL) base.include(ClassMethods) end |
Instance Method Details
#path ⇒ String
path
The path of the represented object, based on the representer name, and the object being represented.
Given ‘UserItemRepresenter`, the following parts are assembled: * ’/user’ * ‘/user/user_uid` if object responds to `user_uid` * `/user/user_uid/item` (or `/user/item`) * `/user/user_uid/item/uid` if object responds to `uid`
37 38 39 40 |
# File 'lib/eipiai/roar/representers/base.rb', line 37 def path parts = path_parts.map { |part| part_path(part) } File.join(*parts) end |
#url(uri = nil) ⇒ String
url
The url of the object.
Based on the input, the result can vary:
65 66 67 68 69 |
# File 'lib/eipiai/roar/representers/base.rb', line 65 def url(uri = nil) uri ||= Eipiai.configuration.base_uri File.join uri.to_s, path end |