representable 0.9.1 → 0.9.2
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/json.rb +2 -2
- data/lib/representable/version.rb +1 -1
- data/lib/representable/xml.rb +8 -5
- data/representable.gemspec +1 -0
- data/test/json_test.rb +6 -0
- data/test/test_helper.rb +1 -1
- data/test/xml_test.rb +9 -0
- metadata +16 -3
data/CHANGES.textile
CHANGED
data/lib/representable/json.rb
CHANGED
@@ -25,9 +25,9 @@ module Representable
|
|
25
25
|
# Example:
|
26
26
|
# book = Book.from_xml("<book><name>Beyond Java</name></book>")
|
27
27
|
# DISCUSS: assumes shitty wrapping like :article => {:name => ...}
|
28
|
-
def from_json(data,
|
28
|
+
def from_json(data, *args, &block)
|
29
29
|
create_from_json.tap do |object|
|
30
|
-
object.from_json(data, &block)
|
30
|
+
object.from_json(data, *args, &block)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/representable/xml.rb
CHANGED
@@ -12,7 +12,6 @@ module Representable
|
|
12
12
|
base.class_eval do
|
13
13
|
include Representable
|
14
14
|
extend ClassMethods
|
15
|
-
alias_method :from_xml, :update_properties_from
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -38,11 +37,9 @@ module Representable
|
|
38
37
|
#
|
39
38
|
# Example:
|
40
39
|
# band.from_xml("<band><name>Nofx</name></band>")
|
41
|
-
def from_xml(
|
42
|
-
xml = Nokogiri::XML::Node.from(data)
|
43
|
-
|
40
|
+
def from_xml(doc, *args, &block)
|
44
41
|
create_from_xml(*args).tap do |object|
|
45
|
-
object.
|
42
|
+
object.from_xml(doc, *args, &block)
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
@@ -52,6 +49,12 @@ module Representable
|
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
52
|
+
def from_xml(doc, *args, &block)
|
53
|
+
xml = Nokogiri::XML::Node.from(doc)
|
54
|
+
update_properties_from(xml, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
55
58
|
# Returns a Nokogiri::XML object representing this object.
|
56
59
|
def to_xml(params={})
|
57
60
|
root_tag = params[:name] || self.class.representation_name
|
data/representable.gemspec
CHANGED
data/test/json_test.rb
CHANGED
@@ -74,6 +74,12 @@ module JsonTest
|
|
74
74
|
assert_equal ["Nofx", nil], [band.name, band.label]
|
75
75
|
end
|
76
76
|
|
77
|
+
it "passes all args to #from_json" do
|
78
|
+
block = lambda {|a,b|}
|
79
|
+
@Band.any_instance.expects(:from_json).with("{}", "yo") # FIXME: how to expect block?
|
80
|
+
@Band.from_json("{}", "yo", &block)
|
81
|
+
end
|
82
|
+
|
77
83
|
# TODO: move following tests to #from_json test.
|
78
84
|
it "raises error with emtpy string" do
|
79
85
|
assert_raises JSON::ParserError do
|
data/test/test_helper.rb
CHANGED
data/test/xml_test.rb
CHANGED
@@ -73,6 +73,15 @@ class XmlTest < MiniTest::Spec
|
|
73
73
|
assert_equal ["Nofx", nil], [@band.name, @band.label]
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
describe ".from_xml" do
|
78
|
+
it "passes all args to #from_xml" do
|
79
|
+
block = lambda {|bind|}
|
80
|
+
@Band.any_instance.expects(:from_xml).with("{}", "yo") # FIXME: how to expect block?
|
81
|
+
@Band.from_xml("{}", "yo", &block)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 2
|
9
|
+
version: 0.9.2
|
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: 2011-11-
|
17
|
+
date: 2011-11-25 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -96,6 +96,19 @@ dependencies:
|
|
96
96
|
version: "2.8"
|
97
97
|
type: :development
|
98
98
|
version_requirements: *id006
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: mocha
|
101
|
+
prerelease: false
|
102
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
type: :development
|
111
|
+
version_requirements: *id007
|
99
112
|
description: Maps representation documents from and to Ruby objects. Includes XML and JSON support, plain properties and compositions.
|
100
113
|
email:
|
101
114
|
- apotonick@gmail.com
|