reptar 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +13 -13
- data/lib/reptar.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35206389420e6c32f120d074467c1658d813fac0
|
4
|
+
data.tar.gz: a83aac419a66c40254cfd98b24fffb46e06bba05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1014332ff0e0656d8a19025a0e573eb0a1622af71b74af29f76d205ebc047883f9611d04854a6261506ee2b884da4a6853c30924bd674c9ea3a0058284b1036
|
7
|
+
data.tar.gz: 75d4f3b1d84742b3f9183e08e4be7049faad62450d0859fc5ea42376f9a1f8a68d480c7a244e472fd1ac1fd4ec576007b214e2a0e2fa0cc330a5f0054fd32c89
|
data/README.md
CHANGED
@@ -20,10 +20,10 @@ Usage
|
|
20
20
|
|
21
21
|
### Attributes
|
22
22
|
|
23
|
-
Inherit `Reptar to build your representation, initialize your Reptar class with your object and get your json output with `to_json`. Declare the fields you want to return with `attribute`
|
23
|
+
Inherit `Reptar` to build your representation, initialize your Reptar class with your object and get your json output with `to_json`. Declare the fields you want to return with `attribute`
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
UserRep < Reptar
|
26
|
+
class UserRep < Reptar
|
27
27
|
attribute :name
|
28
28
|
end
|
29
29
|
|
@@ -35,7 +35,7 @@ UserRep.new(user).to_json
|
|
35
35
|
You can define multiple attributes with `attributes`
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
UserRep < Reptar
|
38
|
+
class UserRep < Reptar
|
39
39
|
attributes :first_name, :last_name, :email
|
40
40
|
end
|
41
41
|
|
@@ -53,7 +53,7 @@ UserRep.new(user).to_json
|
|
53
53
|
If you want to rename an attribute to send a different name in the json output you can use the `key` option.
|
54
54
|
|
55
55
|
```ruby
|
56
|
-
UserRep < Reptar
|
56
|
+
class UserRep < Reptar
|
57
57
|
attribute :name
|
58
58
|
attribute :city, key: :location
|
59
59
|
end
|
@@ -73,7 +73,7 @@ UserRep.new(user).to_json
|
|
73
73
|
Send your custom methods as attributes to return their results to the json output.
|
74
74
|
|
75
75
|
```ruby
|
76
|
-
PostRep < Reptar
|
76
|
+
class PostRep < Reptar
|
77
77
|
attributes :title, :slug
|
78
78
|
|
79
79
|
def slug
|
@@ -112,7 +112,7 @@ UserRep.new(user).to_json(root: :user)
|
|
112
112
|
You can initialize your representation class with an array of objects to return the output of each one.
|
113
113
|
|
114
114
|
```ruby
|
115
|
-
UserRep < Reptar
|
115
|
+
class UserRep < Reptar
|
116
116
|
attributes :name
|
117
117
|
end
|
118
118
|
|
@@ -135,7 +135,7 @@ UserRep.new(users).to_json
|
|
135
135
|
`collection` method is available to be more explicit in your representation.
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
UserRep < Reptar
|
138
|
+
class UserRep < Reptar
|
139
139
|
attribute :name
|
140
140
|
collection :languages
|
141
141
|
end
|
@@ -155,12 +155,12 @@ UserRep.new(user).to_json
|
|
155
155
|
You can associate your representation class with another using the `with` option, this is useful for return a nested output.
|
156
156
|
|
157
157
|
```ruby
|
158
|
-
UserRep < Reptar
|
158
|
+
class UserRep < Reptar
|
159
159
|
attributes :name, :email
|
160
160
|
attribute :company, with: "CompanyRep"
|
161
161
|
end
|
162
162
|
|
163
|
-
CompanyRep < Reptar
|
163
|
+
class CompanyRep < Reptar
|
164
164
|
attributes :name, :city
|
165
165
|
end
|
166
166
|
|
@@ -179,15 +179,15 @@ UserRep.new(user).to_json
|
|
179
179
|
}
|
180
180
|
```
|
181
181
|
|
182
|
-
You are free to also use `collection for define your asocciations.
|
182
|
+
You are free to also use `collection` for define your asocciations.
|
183
183
|
|
184
184
|
```ruby
|
185
|
-
UserRep < Reptar
|
185
|
+
class UserRep < Reptar
|
186
186
|
attributes :name, :email
|
187
187
|
collection :posts, with: "PostRep"
|
188
188
|
end
|
189
189
|
|
190
|
-
PostRep < Reptar
|
190
|
+
class PostRep < Reptar
|
191
191
|
attributes :title, :content
|
192
192
|
end
|
193
193
|
|
@@ -216,4 +216,4 @@ UserRep.new(user).to_json
|
|
216
216
|
}
|
217
217
|
]
|
218
218
|
}
|
219
|
-
```
|
219
|
+
```
|
data/lib/reptar.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
require "json"
|
21
21
|
|
22
22
|
class Reptar
|
23
|
-
VERSION = "1.0.
|
23
|
+
VERSION = "1.0.1"
|
24
24
|
|
25
25
|
class << self; attr_reader :nodes; end
|
26
26
|
|
@@ -36,10 +36,6 @@ class Reptar
|
|
36
36
|
attributes.each{ |e| @nodes[e] = nil }
|
37
37
|
end
|
38
38
|
|
39
|
-
def self.method_missing(method_name, *args)
|
40
|
-
method_name == :collection ? self.send(:attribute, *args) : super
|
41
|
-
end
|
42
|
-
|
43
39
|
def initialize(object)
|
44
40
|
@object = object
|
45
41
|
end
|
@@ -67,4 +63,6 @@ class Reptar
|
|
67
63
|
hash[name] = res
|
68
64
|
end
|
69
65
|
end
|
66
|
+
|
67
|
+
class << self; alias_method :collection, :attribute; end
|
70
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reptar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Lopez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|