dozuki-mapper 0.1.1 → 0.1.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/lib/dozuki-mapper.rb +1 -4
- data/lib/dozuki-mapper/version.rb +1 -1
- data/spec/dozuki-mapper_spec.rb +12 -21
- metadata +2 -2
data/lib/dozuki-mapper.rb
CHANGED
@@ -5,9 +5,6 @@ module Dozuki
|
|
5
5
|
def self.included(base)
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
|
-
def map_from(node)
|
9
|
-
self.class.mapper.call Proxy.new(self, node)
|
10
|
-
end
|
11
8
|
module ClassMethods
|
12
9
|
def map_with(&blk)
|
13
10
|
@mapper = blk
|
@@ -17,7 +14,7 @@ module Dozuki
|
|
17
14
|
end
|
18
15
|
def from_node(node)
|
19
16
|
new.tap do |instance|
|
20
|
-
|
17
|
+
mapper.call Proxy.new(instance, node)
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
data/spec/dozuki-mapper_spec.rb
CHANGED
@@ -7,16 +7,24 @@ module Dozuki
|
|
7
7
|
before do
|
8
8
|
klass.send(:include, Mapper)
|
9
9
|
end
|
10
|
-
describe "
|
11
|
-
let(:
|
10
|
+
describe "from_node" do
|
11
|
+
let(:node) { mock :node }
|
12
|
+
let(:instance) { mock :klass }
|
12
13
|
let(:proxy) { mock :proxy }
|
13
|
-
before
|
14
|
+
before do
|
15
|
+
Mapper::Proxy.stub(:new).and_return(proxy)
|
16
|
+
klass.stub(:new).and_return(instance)
|
17
|
+
end
|
14
18
|
subject {
|
15
19
|
klass.map_with do |arg|
|
16
20
|
@called_with = arg
|
17
21
|
end
|
18
|
-
|
22
|
+
klass.from_node(node)
|
19
23
|
}
|
24
|
+
it "should create a new instance of the class" do
|
25
|
+
klass.should_receive(:new).and_return(instance)
|
26
|
+
subject
|
27
|
+
end
|
20
28
|
it "should create a new proxy with the node and the mapper" do
|
21
29
|
Mapper::Proxy.should_receive(:new).with(instance, node).and_return(proxy)
|
22
30
|
subject
|
@@ -25,23 +33,6 @@ module Dozuki
|
|
25
33
|
subject
|
26
34
|
@called_with.should == proxy
|
27
35
|
end
|
28
|
-
end
|
29
|
-
describe "from_node" do
|
30
|
-
let(:node) { mock :node }
|
31
|
-
let(:instance) { mock :klass }
|
32
|
-
before do
|
33
|
-
klass.stub(:new).and_return(instance)
|
34
|
-
instance.stub(:map_from)
|
35
|
-
end
|
36
|
-
subject { klass.from_node(node) }
|
37
|
-
it "should create a new instance of the class" do
|
38
|
-
klass.should_receive(:new).and_return(instance)
|
39
|
-
subject
|
40
|
-
end
|
41
|
-
it "should map the instance from the node" do
|
42
|
-
instance.should_receive(:map_from).with(node)
|
43
|
-
subject
|
44
|
-
end
|
45
36
|
it "should return the instance of the class" do
|
46
37
|
subject.should == instance
|
47
38
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dozuki-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Almond
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-21 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|