api-presenter 0.0.3 → 0.0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -9
- data/lib/api/presenter/hypermedia.rb +1 -1
- data/lib/api/presenter/resource.rb +1 -2
- data/lib/api/presenter/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Api::Presenter
|
2
2
|
|
3
3
|
This gem builds the basics for presenting your data using the media type described in the [api doc](https://github.com/ncuesta/api-doc). Here you will find classes to represent your resources
|
4
|
-
and also the functions to convert them to
|
4
|
+
and also the functions to convert them to a ruby hash. It's your decision how to export them.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -75,7 +75,7 @@ class Person
|
|
75
75
|
end
|
76
76
|
```
|
77
77
|
|
78
|
-
And that's it, now we can get the representation in
|
78
|
+
And that's it, now we can get the representation in a hash using.
|
79
79
|
|
80
80
|
```ruby
|
81
81
|
data = Person.new("Alvaro", 27)
|
@@ -86,7 +86,7 @@ resource.present # or Api::Presenter::Hypermedia.present resource
|
|
86
86
|
```
|
87
87
|
|
88
88
|
It will look like this:
|
89
|
-
```
|
89
|
+
```ruby
|
90
90
|
{
|
91
91
|
"links":
|
92
92
|
{
|
@@ -102,15 +102,14 @@ It will look like this:
|
|
102
102
|
### Related resources
|
103
103
|
|
104
104
|
It's very common that our model is related to others, and we may want to show this in our representation.
|
105
|
-
To do so, need to create a resource class for each one and add them
|
106
|
-
hypermedia_properties.
|
105
|
+
To do so, need to create a resource class for each one and add them as a new property.
|
107
106
|
|
108
107
|
Using the example above, now our person has a dog. So:
|
109
108
|
|
110
109
|
```ruby
|
111
110
|
class DogResource < Api::Presenter::Resource
|
112
|
-
property name
|
113
|
-
property owner
|
111
|
+
property :name
|
112
|
+
property :owner
|
114
113
|
|
115
114
|
def self_link
|
116
115
|
"/dog/#{@resource.name}"
|
@@ -151,7 +150,7 @@ person_resource.present # Api::Presenter::Hypermedia.present person_resource
|
|
151
150
|
|
152
151
|
It will look like this:
|
153
152
|
|
154
|
-
```
|
153
|
+
```ruby
|
155
154
|
{
|
156
155
|
"links":
|
157
156
|
{
|
@@ -334,7 +333,6 @@ def custom_link
|
|
334
333
|
"/path/to/custom_link"
|
335
334
|
end
|
336
335
|
|
337
|
-
|
338
336
|
def custom_link?(options = {})
|
339
337
|
a_condition_that_determins_if_it_should_be_displayed returning true or false
|
340
338
|
end
|
@@ -15,7 +15,7 @@ module Api
|
|
15
15
|
# simlple fields(Dates, numbers, etc.) and also more
|
16
16
|
# complex ones that may be subject of expansion.
|
17
17
|
def present_properties(resource, representation)
|
18
|
-
resource_properties = resource.class.properties
|
18
|
+
resource_properties = resource.class.properties.dup
|
19
19
|
|
20
20
|
# Special treatment for entries
|
21
21
|
entries_property = resource_properties.delete(:entries)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3
|
4
|
+
version: 0.0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|