datamapa 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -19
- data/Gemfile.lock +2 -1
- data/README.md +4 -4
- data/lib/datamapa/version.rb +1 -1
- data/spec/datamapa/datamapa_spec.rb +182 -180
- metadata +59 -49
data/.gitignore
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
|
4
|
-
.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
test/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.swp
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
Session.vim
|
16
|
+
|
17
|
+
# YARD artifacts
|
18
|
+
.yardoc
|
19
|
+
_yardoc
|
20
|
+
doc/
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
datamapa
|
2
|
-
========
|
3
|
-
|
4
|
-
A minimalistic Data Mapper for removing model dependency on Active Record
|
1
|
+
datamapa
|
2
|
+
========
|
3
|
+
|
4
|
+
A minimalistic Data Mapper for removing model dependency on Active Record
|
data/lib/datamapa/version.rb
CHANGED
@@ -1,180 +1,182 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
let(:
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
model.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
ar.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
let(:
|
60
|
-
let(:
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
model.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
ar.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
let(:
|
89
|
-
let(:
|
90
|
-
let(:
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
model.
|
102
|
-
|
103
|
-
model.
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
model.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
ar.
|
121
|
-
|
122
|
-
ar.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
ar.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
let(:
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
model.
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
ar.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
let(:
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
model.
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
ar.
|
178
|
-
|
179
|
-
|
180
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'mocha/setup'
|
5
|
+
require 'datamapa'
|
6
|
+
|
7
|
+
describe DataMapa do
|
8
|
+
|
9
|
+
def class_with_attributes(attributes)
|
10
|
+
Class.new do
|
11
|
+
attributes.each do |attr|
|
12
|
+
attr_accessor attr
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def mapper_class(ar_class, model_class, attributes)
|
18
|
+
Class.new do
|
19
|
+
include DataMapa
|
20
|
+
|
21
|
+
active_record_class ar_class
|
22
|
+
model_constructor model_class.method(:new)
|
23
|
+
simple_attr attributes[:simple] || []
|
24
|
+
ref_attr attributes[:ref] || {}
|
25
|
+
collection_attr attributes[:collection] || {}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let (:any_object) { Object.new }
|
30
|
+
|
31
|
+
describe "simple attribute" do
|
32
|
+
let(:ar_class) { class_with_attributes([:id, :a1]) }
|
33
|
+
let(:model_class) { class_with_attributes([:id, :a1]) }
|
34
|
+
let(:mapper) { mapper_class(
|
35
|
+
ar_class, model_class,
|
36
|
+
simple: [:id, :a1]
|
37
|
+
) }
|
38
|
+
|
39
|
+
it "converts to model" do
|
40
|
+
ar = stub(id: 1, a1: 'any string')
|
41
|
+
|
42
|
+
model = mapper.to_model(ar)
|
43
|
+
|
44
|
+
model.id.must_equal ar.id
|
45
|
+
model.a1.must_equal ar.a1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "converts to ar" do
|
49
|
+
model = stub(id: nil, a1: 'any string')
|
50
|
+
|
51
|
+
ar = mapper.to_ar(model)
|
52
|
+
|
53
|
+
ar.id.must_equal model.id
|
54
|
+
ar.a1.must_equal model.a1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "ref attribute" do
|
59
|
+
let(:ar_class) { class_with_attributes([:id, :a1_id]) }
|
60
|
+
let(:model_class) { class_with_attributes([:id, :a1]) }
|
61
|
+
let(:a1_model) { any_object }
|
62
|
+
let(:mapper) { mapper_class(
|
63
|
+
ar_class, model_class,
|
64
|
+
simple: [:id],
|
65
|
+
ref: { a1: stub(to_model: a1_model) }
|
66
|
+
) }
|
67
|
+
|
68
|
+
it "converts to model without option" do
|
69
|
+
ar = stub(id: 1, a1: nil)
|
70
|
+
|
71
|
+
model = mapper.to_model(ar)
|
72
|
+
|
73
|
+
model.id.must_equal ar.id
|
74
|
+
model.a1.must_equal a1_model
|
75
|
+
end
|
76
|
+
|
77
|
+
it "converts to AR" do
|
78
|
+
model = stub(id: nil, a1: stub(id: 10))
|
79
|
+
|
80
|
+
ar = mapper.to_ar(model)
|
81
|
+
|
82
|
+
ar.id.must_equal model.id
|
83
|
+
ar.a1_id.must_equal model.a1.id
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "collection attribute" do
|
88
|
+
let(:ar_class) { class_with_attributes([:id, :a1]) }
|
89
|
+
let(:model_class) { class_with_attributes([:id, :a1]) }
|
90
|
+
let(:a1_model) { any_object }
|
91
|
+
let(:a1_ar) { any_object }
|
92
|
+
let(:mapper) { mapper_class(
|
93
|
+
ar_class, model_class,
|
94
|
+
simple: [:id],
|
95
|
+
collection: {a1: stub(to_model: a1_model, to_ar: a1_ar)}
|
96
|
+
) }
|
97
|
+
|
98
|
+
it "converts to model with option" do
|
99
|
+
ar = stub(id: 1, a1: [Object.new, Object.new])
|
100
|
+
|
101
|
+
model = mapper.to_model(ar, include: [:a1])
|
102
|
+
|
103
|
+
model.id.must_equal ar.id
|
104
|
+
model.a1[0].must_equal a1_model
|
105
|
+
model.a1[1].must_equal a1_model
|
106
|
+
end
|
107
|
+
|
108
|
+
it "does not convert to model without option" do
|
109
|
+
ar = stub(id: 1, a1: [Object.new, Object.new])
|
110
|
+
|
111
|
+
model = mapper.to_model(ar)
|
112
|
+
|
113
|
+
model.id.must_equal ar.id
|
114
|
+
model.a1.must_equal nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "converts to AR with option" do
|
118
|
+
model = stub(id: nil, a1: [Object.new, Object.new])
|
119
|
+
|
120
|
+
ar = mapper.to_ar(model, include: [:a1])
|
121
|
+
|
122
|
+
ar.id.must_equal model.id
|
123
|
+
ar.a1[0].must_equal a1_ar
|
124
|
+
ar.a1[1].must_equal a1_ar
|
125
|
+
end
|
126
|
+
|
127
|
+
it "does not convert to AR without option" do
|
128
|
+
model = stub(id: nil, a1: [Object.new, Object.new])
|
129
|
+
|
130
|
+
ar = mapper.to_ar(model)
|
131
|
+
|
132
|
+
ar.id.must_equal model.id
|
133
|
+
ar.a1.must_equal nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "attribute in AR only" do
|
138
|
+
let(:ar_class) { class_with_attributes([:id, :a1]) }
|
139
|
+
let(:model_class) { class_with_attributes([:id]) }
|
140
|
+
let(:mapper) { mapper_class(ar_class, model_class, simple: [:id]) }
|
141
|
+
|
142
|
+
it "converts to model" do
|
143
|
+
ar = stub(id: 1, a1: 'any string')
|
144
|
+
|
145
|
+
model = mapper.to_model(ar)
|
146
|
+
|
147
|
+
model.id.must_equal ar.id
|
148
|
+
end
|
149
|
+
|
150
|
+
it "converts to AR" do
|
151
|
+
model = stub(id: nil)
|
152
|
+
|
153
|
+
ar = mapper.to_ar(model)
|
154
|
+
|
155
|
+
ar.id.must_equal model.id
|
156
|
+
ar.a1.must_equal nil
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "attribute in model only" do
|
161
|
+
let(:ar_class) { class_with_attributes([:id]) }
|
162
|
+
let(:model_class) { class_with_attributes([:id, :a1]) }
|
163
|
+
let(:mapper) { mapper_class(ar_class, model_class, simple: [:id]) }
|
164
|
+
|
165
|
+
it "converts to model" do
|
166
|
+
ar = stub(id: 1)
|
167
|
+
|
168
|
+
model = mapper.to_model(ar)
|
169
|
+
|
170
|
+
model.id.must_equal ar.id
|
171
|
+
model.a1.must_equal nil
|
172
|
+
end
|
173
|
+
|
174
|
+
it "converts to AR" do
|
175
|
+
model = stub(id: nil, a1: 'any string')
|
176
|
+
|
177
|
+
ar = mapper.to_ar(model)
|
178
|
+
|
179
|
+
ar.id.must_equal model.id
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: datamapa
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Yosuke Doi
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2013-06-08 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: minitest
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
22
|
prerelease: false
|
24
|
-
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
38
31
|
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mocha
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
37
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
46
|
description: A minimalistic Data Mapper for removing model dependency on Active Record
|
47
|
-
email:
|
47
|
+
email:
|
48
48
|
- doinchi@gmail.com
|
49
49
|
executables: []
|
50
|
+
|
50
51
|
extensions: []
|
52
|
+
|
51
53
|
extra_rdoc_files: []
|
52
|
-
|
54
|
+
|
55
|
+
files:
|
53
56
|
- .gitignore
|
54
57
|
- Gemfile
|
55
58
|
- Gemfile.lock
|
@@ -60,30 +63,37 @@ files:
|
|
60
63
|
- lib/datamapa.rb
|
61
64
|
- lib/datamapa/version.rb
|
62
65
|
- spec/datamapa/datamapa_spec.rb
|
66
|
+
has_rdoc: true
|
63
67
|
homepage: http://rubygems.org/gems/datamapa
|
64
|
-
licenses:
|
68
|
+
licenses:
|
65
69
|
- MIT
|
66
70
|
post_install_message:
|
67
71
|
rdoc_options: []
|
68
|
-
|
72
|
+
|
73
|
+
require_paths:
|
69
74
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
76
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
84
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
82
91
|
requirements: []
|
92
|
+
|
83
93
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.3.7
|
85
95
|
signing_key:
|
86
96
|
specification_version: 3
|
87
97
|
summary: Data Mapper using Active Record
|
88
|
-
test_files:
|
98
|
+
test_files:
|
89
99
|
- spec/datamapa/datamapa_spec.rb
|