representable 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ h2. 0.9.2
2
+
3
+ * Arguments and block now successfully forwarded in @#from_*@.
4
+
1
5
  h2. 0.9.1
2
6
 
3
7
  * Extracted common serialization into @Representable#create_representation_with@ and deserialization into @#update_properties_from@.
@@ -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, options={}, &block)
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
 
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -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(data, *args)
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.update_properties_from(xml)
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
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency "rake"
27
27
  s.add_development_dependency "test_xml"
28
28
  s.add_development_dependency "minitest", "~>2.8"
29
+ s.add_development_dependency "mocha"
29
30
  end
@@ -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
@@ -5,4 +5,4 @@ require 'representable'
5
5
  require 'test/unit'
6
6
  require 'minitest/spec'
7
7
  require 'test_xml/mini_test'
8
-
8
+ require 'mocha'
@@ -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
- - 1
9
- version: 0.9.1
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-22 00:00:00 -02:00
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