representable 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.textile +4 -0
- data/lib/representable.rb +3 -4
- data/lib/representable/version.rb +1 -1
- data/representable.gemspec +1 -0
- data/test/json_bindings_test.rb +0 -1
- data/test/json_test.rb +0 -1
- data/test/mongoid_test.rb +31 -0
- data/test/representable_test.rb +2 -3
- data/test/test_helper.rb +1 -0
- metadata +17 -3
data/CHANGES.textile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
h2. 1.1.1
|
2
|
+
|
3
|
+
* When a representer module is extended we no longer set the <code>@representable_attrs</code> ivar directly but use a setter. This makes it work with mongoid and fixes https://github.com/apotonick/roar/issues/10.
|
4
|
+
|
1
5
|
h2. 1.1.0
|
2
6
|
|
3
7
|
* Added `JSON::Collection` to have plain list representations. And `JSON::Hash` for hashes.
|
data/lib/representable.rb
CHANGED
@@ -25,6 +25,8 @@ require 'representable/definition'
|
|
25
25
|
#
|
26
26
|
# hero.extend(HeroRepresenter).to_json
|
27
27
|
module Representable
|
28
|
+
attr_writer :representable_attrs
|
29
|
+
|
28
30
|
def self.included(base)
|
29
31
|
base.class_eval do
|
30
32
|
extend ClassMethods
|
@@ -37,10 +39,7 @@ module Representable
|
|
37
39
|
|
38
40
|
# Copies the representable_attrs to the extended object.
|
39
41
|
def self.extended(object)
|
40
|
-
|
41
|
-
object.instance_eval do
|
42
|
-
@representable_attrs = attrs
|
43
|
-
end
|
42
|
+
object.representable_attrs=(representable_attrs)
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
data/representable.gemspec
CHANGED
data/test/json_bindings_test.rb
CHANGED
data/test/json_test.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mongoid'
|
3
|
+
require 'mongoid/document'
|
4
|
+
|
5
|
+
class MongoidTest < MiniTest::Spec
|
6
|
+
describe "Mongoid compatibility" do
|
7
|
+
it "allows #to_json" do
|
8
|
+
class Profile
|
9
|
+
include Mongoid::Document
|
10
|
+
field :name
|
11
|
+
end
|
12
|
+
|
13
|
+
class Dude
|
14
|
+
include Mongoid::Document
|
15
|
+
embeds_one :profile, :class_name => "MongoidTest::Profile"
|
16
|
+
end
|
17
|
+
|
18
|
+
module ProfileRepresenter
|
19
|
+
include Representable::JSON
|
20
|
+
|
21
|
+
property :name
|
22
|
+
end
|
23
|
+
|
24
|
+
dude = Dude.new
|
25
|
+
dude.profile = Profile.new
|
26
|
+
dude.profile.name = "Kofi"
|
27
|
+
|
28
|
+
assert_equal "{\"name\":\"Kofi\"}", dude.profile.extend(ProfileRepresenter).to_json
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/representable_test.rb
CHANGED
@@ -56,7 +56,6 @@ class RepresentableTest < MiniTest::Spec
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "allows including the concrete representer module later" do
|
59
|
-
require 'representable/json'
|
60
59
|
vd = class VD
|
61
60
|
attr_accessor :name, :street_cred
|
62
61
|
include Representable::JSON
|
@@ -199,7 +198,7 @@ class RepresentableTest < MiniTest::Spec
|
|
199
198
|
end
|
200
199
|
|
201
200
|
|
202
|
-
|
201
|
+
# DISCUSS: i don't like the JSON requirement here, what about some generic test module?
|
203
202
|
class PopBand
|
204
203
|
include Representable::JSON
|
205
204
|
property :name
|
@@ -293,6 +292,6 @@ class RepresentableTest < MiniTest::Spec
|
|
293
292
|
it "allows mapping formats to representers" do
|
294
293
|
assert_equal :whatever, @class.representer[:json]
|
295
294
|
assert_equal :special, @class.representer["application/order-json"]
|
296
|
-
end
|
295
|
+
end
|
297
296
|
end
|
298
297
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nick Sutterer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-02-
|
17
|
+
date: 2012-02-06 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -97,6 +97,19 @@ dependencies:
|
|
97
97
|
version: "0"
|
98
98
|
type: :development
|
99
99
|
version_requirements: *id006
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: mongoid
|
102
|
+
prerelease: false
|
103
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
type: :development
|
112
|
+
version_requirements: *id007
|
100
113
|
description: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties, collections and compositions.
|
101
114
|
email:
|
102
115
|
- apotonick@gmail.com
|
@@ -131,6 +144,7 @@ files:
|
|
131
144
|
- test/definition_test.rb
|
132
145
|
- test/json_bindings_test.rb
|
133
146
|
- test/json_test.rb
|
147
|
+
- test/mongoid_test.rb
|
134
148
|
- test/polymorphic_test.rb
|
135
149
|
- test/representable_test.rb
|
136
150
|
- test/test_helper.rb
|