Module: Darstellung::Representable
- Includes:
- Definable
- Defined in:
- lib/darstellung/representable.rb
Overview
This module is included into resources that need a summary and detail view for display in APIs. Summary views are for display in lists, detail views are generally show actions.
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
- #resource The resource being represented.(Theresourcebeingrepresented.) ⇒ Object readonly
Class Method Summary collapse
-
.included(klass) ⇒ Object
Including the module will inject the necessary macros into the base class.
Instance Method Summary collapse
-
#collection(version = nil) ⇒ Hash
Gets the collection view for a specific version of the resource.
-
#detail(version = nil) ⇒ Hash
Gets the detail view for a specific version of the resource.
-
#initialize(resource) ⇒ Object
Initialize the new representation with the provided resource.
-
#summary(version = nil) ⇒ Hash
Gets the summary view for a specific version of the resource.
Methods included from Definable
#detail_attributes, #summary_attributes
Instance Attribute Details
#resource ⇒ Object (readonly)
17 18 19 |
# File 'lib/darstellung/representable.rb', line 17 def resource @resource end |
#resource The resource being represented.(Theresourcebeingrepresented.) ⇒ Object (readonly)
17 |
# File 'lib/darstellung/representable.rb', line 17 attr_reader :resource |
Class Method Details
.included(klass) ⇒ Object
Including the module will inject the necessary macros into the base class.
121 122 123 |
# File 'lib/darstellung/representable.rb', line 121 def included(klass) klass.extend(Macros) end |
Instance Method Details
#collection(version = nil) ⇒ Hash
The collection representation is a list of summary representations.
Gets the collection view for a specific version of the resource. If no version is provided then we assume from “0.0.0” which will render attributes available in all versions of the API.
33 34 35 |
# File 'lib/darstellung/representable.rb', line 33 def collection(version = nil) representation(version, multiple(summary_attributes, version)) end |
#detail(version = nil) ⇒ Hash
Gets the detail view for a specific version of the resource. If no version is provided then we assume from “0.0.0” which will render attributes available in all versions of the API.
49 50 51 |
# File 'lib/darstellung/representable.rb', line 49 def detail(version = nil) representation(version, single(detail_attributes, resource, version)) end |
#initialize(resource) ⇒ Object
Initialize the new representation with the provided resource.
65 66 67 |
# File 'lib/darstellung/representable.rb', line 65 def initialize(resource) @resource = resource end |
#summary(version = nil) ⇒ Hash
Gets the summary view for a specific version of the resource. If no version is provided then we assume from “0.0.0” which will render attributes available in all versions of the API.
81 82 83 |
# File 'lib/darstellung/representable.rb', line 81 def summary(version = nil) representation(version, single(summary_attributes, resource, version)) end |