datamapa 0.0.2 → 0.0.3

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/.gitignore CHANGED
@@ -1,19 +1,20 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
- Session.vim
15
-
16
- # YARD artifacts
17
- .yardoc
18
- _yardoc
19
- doc/
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/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- datamapa (0.0.1)
4
+ datamapa (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,7 @@ GEM
12
12
  metaclass (~> 0.0.1)
13
13
 
14
14
  PLATFORMS
15
+ ruby
15
16
  x86-mingw32
16
17
 
17
18
  DEPENDENCIES
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
@@ -1,3 +1,3 @@
1
1
  module DataMapa
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,180 +1,182 @@
1
- require 'minitest/autorun'
2
- require 'mocha/setup'
3
- require 'datamapa'
4
-
5
- describe DataMapa do
6
-
7
- def class_with_attributes(attributes)
8
- Class.new do
9
- attributes.each do |attr|
10
- attr_accessor attr
11
- end
12
- end
13
- end
14
-
15
- def mapper_class(ar_class, model_class, attributes)
16
- Class.new do
17
- include DataMapa
18
-
19
- active_record_class ar_class
20
- model_constructor model_class.method(:new)
21
- simple_attr attributes[:simple] || []
22
- ref_attr attributes[:ref] || {}
23
- collection_attr attributes[:collection] || {}
24
- end
25
- end
26
-
27
- let (:any_object) { Object.new }
28
-
29
- describe "simple attribute" do
30
- let(:ar_class) { class_with_attributes([:id, :a1]) }
31
- let(:model_class) { class_with_attributes([:id, :a1]) }
32
- let(:mapper) { mapper_class(
33
- ar_class, model_class,
34
- simple: [:id, :a1]
35
- ) }
36
-
37
- it "converts to model" do
38
- ar = stub(id: 1, a1: 'any string')
39
-
40
- model = mapper.to_model(ar)
41
-
42
- model.id.must_equal ar.id
43
- model.a1.must_equal ar.a1
44
- end
45
-
46
- it "converts to ar" do
47
- model = stub(id: nil, a1: 'any string')
48
-
49
- ar = mapper.to_ar(model)
50
-
51
- ar.id.must_equal model.id
52
- ar.a1.must_equal model.a1
53
- end
54
- end
55
-
56
- describe "ref attribute" do
57
- let(:ar_class) { class_with_attributes([:id, :a1_id]) }
58
- let(:model_class) { class_with_attributes([:id, :a1]) }
59
- let(:a1_model) { any_object }
60
- let(:mapper) { mapper_class(
61
- ar_class, model_class,
62
- simple: [:id],
63
- ref: { a1: stub(to_model: a1_model) }
64
- ) }
65
-
66
- it "converts to model without option" do
67
- ar = stub(id: 1, a1: nil)
68
-
69
- model = mapper.to_model(ar)
70
-
71
- model.id.must_equal ar.id
72
- model.a1.must_equal a1_model
73
- end
74
-
75
- it "converts to AR" do
76
- model = stub(id: nil, a1: stub(id: 10))
77
-
78
- ar = mapper.to_ar(model)
79
-
80
- ar.id.must_equal model.id
81
- ar.a1_id.must_equal model.a1.id
82
- end
83
- end
84
-
85
- describe "collection attribute" do
86
- let(:ar_class) { class_with_attributes([:id, :a1]) }
87
- let(:model_class) { class_with_attributes([:id, :a1]) }
88
- let(:a1_model) { any_object }
89
- let(:a1_ar) { any_object }
90
- let(:mapper) { mapper_class(
91
- ar_class, model_class,
92
- simple: [:id],
93
- collection: {a1: stub(to_model: a1_model, to_ar: a1_ar)}
94
- ) }
95
-
96
- it "converts to model with option" do
97
- ar = stub(id: 1, a1: [Object.new, Object.new])
98
-
99
- model = mapper.to_model(ar, include: [:a1])
100
-
101
- model.id.must_equal ar.id
102
- model.a1[0].must_equal a1_model
103
- model.a1[1].must_equal a1_model
104
- end
105
-
106
- it "does not convert to model without option" do
107
- ar = stub(id: 1, a1: [Object.new, Object.new])
108
-
109
- model = mapper.to_model(ar)
110
-
111
- model.id.must_equal ar.id
112
- model.a1.must_equal nil
113
- end
114
-
115
- it "converts to AR with option" do
116
- model = stub(id: nil, a1: [Object.new, Object.new])
117
-
118
- ar = mapper.to_ar(model, include: [:a1])
119
-
120
- ar.id.must_equal model.id
121
- ar.a1[0].must_equal a1_ar
122
- ar.a1[1].must_equal a1_ar
123
- end
124
-
125
- it "does not convert to AR without option" do
126
- model = stub(id: nil, a1: [Object.new, Object.new])
127
-
128
- ar = mapper.to_ar(model)
129
-
130
- ar.id.must_equal model.id
131
- ar.a1.must_equal nil
132
- end
133
- end
134
-
135
- describe "attribute in AR only" do
136
- let(:ar_class) { class_with_attributes([:id, :a1]) }
137
- let(:model_class) { class_with_attributes([:id]) }
138
- let(:mapper) { mapper_class(ar_class, model_class, simple: [:id]) }
139
-
140
- it "converts to model" do
141
- ar = stub(id: 1, a1: 'any string')
142
-
143
- model = mapper.to_model(ar)
144
-
145
- model.id.must_equal ar.id
146
- end
147
-
148
- it "converts to AR" do
149
- model = stub(id: nil)
150
-
151
- ar = mapper.to_ar(model)
152
-
153
- ar.id.must_equal model.id
154
- ar.a1.must_equal nil
155
- end
156
- end
157
-
158
- describe "attribute in model only" do
159
- let(:ar_class) { class_with_attributes([:id]) }
160
- let(:model_class) { class_with_attributes([:id, :a1]) }
161
- let(:mapper) { mapper_class(ar_class, model_class, simple: [:id]) }
162
-
163
- it "converts to model" do
164
- ar = stub(id: 1)
165
-
166
- model = mapper.to_model(ar)
167
-
168
- model.id.must_equal ar.id
169
- model.a1.must_equal nil
170
- end
171
-
172
- it "converts to AR" do
173
- model = stub(id: nil, a1: 'any string')
174
-
175
- ar = mapper.to_ar(model)
176
-
177
- ar.id.must_equal model.id
178
- end
179
- end
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
- version: 0.0.2
5
- prerelease:
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
- date: 2013-06-08 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
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
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: mocha
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
- version_requirements: !ruby/object:Gem::Requirement
36
+ requirement: &id002 !ruby/object:Gem::Requirement
41
37
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
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
- files:
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
- require_paths:
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
- version: '0'
76
- required_rubygems_version: !ruby/object:Gem::Requirement
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
- version: '0'
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.8.24
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