rom-mapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +3 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +21 -0
  6. data/Gemfile +19 -0
  7. data/Gemfile.devtools +55 -0
  8. data/Guardfile +19 -0
  9. data/LICENSE +20 -0
  10. data/README.md +21 -0
  11. data/Rakefile +7 -0
  12. data/config/devtools.yml +2 -0
  13. data/config/flay.yml +3 -0
  14. data/config/flog.yml +2 -0
  15. data/config/mutant.yml +3 -0
  16. data/config/reek.yml +105 -0
  17. data/config/rubocop.yml +45 -0
  18. data/lib/rom-mapper.rb +17 -0
  19. data/lib/rom/mapper.rb +135 -0
  20. data/lib/rom/mapper/attribute.rb +26 -0
  21. data/lib/rom/mapper/dumper.rb +27 -0
  22. data/lib/rom/mapper/header.rb +78 -0
  23. data/lib/rom/mapper/loader.rb +22 -0
  24. data/lib/rom/mapper/loader/allocator.rb +32 -0
  25. data/lib/rom/mapper/loader/attribute_writer.rb +23 -0
  26. data/lib/rom/mapper/loader/object_builder.rb +28 -0
  27. data/lib/rom/version.rb +11 -0
  28. data/rom-mapper.gemspec +23 -0
  29. data/spec/shared/unit/loader_call.rb +13 -0
  30. data/spec/shared/unit/loader_identity.rb +13 -0
  31. data/spec/shared/unit/mapper_context.rb +13 -0
  32. data/spec/spec_helper.rb +48 -0
  33. data/spec/unit/rom/mapper/call_spec.rb +32 -0
  34. data/spec/unit/rom/mapper/class_methods/build_spec.rb +64 -0
  35. data/spec/unit/rom/mapper/dump_spec.rb +15 -0
  36. data/spec/unit/rom/mapper/dumper/call_spec.rb +29 -0
  37. data/spec/unit/rom/mapper/dumper/identity_spec.rb +28 -0
  38. data/spec/unit/rom/mapper/header/each_spec.rb +28 -0
  39. data/spec/unit/rom/mapper/header/element_reader_spec.rb +25 -0
  40. data/spec/unit/rom/mapper/header/keys_spec.rb +32 -0
  41. data/spec/unit/rom/mapper/identity_from_tuple_spec.rb +15 -0
  42. data/spec/unit/rom/mapper/identity_spec.rb +15 -0
  43. data/spec/unit/rom/mapper/load_spec.rb +15 -0
  44. data/spec/unit/rom/mapper/loader/allocator/call_spec.rb +7 -0
  45. data/spec/unit/rom/mapper/loader/allocator/identity_spec.rb +7 -0
  46. data/spec/unit/rom/mapper/loader/attribute_writer/call_spec.rb +7 -0
  47. data/spec/unit/rom/mapper/loader/attribute_writer/identity_spec.rb +7 -0
  48. data/spec/unit/rom/mapper/loader/object_builder/call_spec.rb +7 -0
  49. data/spec/unit/rom/mapper/loader/object_builder/identity_spec.rb +7 -0
  50. data/spec/unit/rom/mapper/model_spec.rb +11 -0
  51. data/spec/unit/rom/mapper/new_object_spec.rb +14 -0
  52. metadata +177 -0
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#dump' do
6
+ include_context 'Mapper'
7
+
8
+ it 'dumps the object into data tuple' do
9
+ stub(dumper).call(object) { data }
10
+
11
+ expect(mapper.dump(object)).to be(data)
12
+
13
+ dumper.should have_received.call(object)
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Dumper, '#call' do
6
+ subject(:dumper) { described_class.new(header) }
7
+
8
+ let(:header) { Mapper::Header.build([[:uid, Integer], [:name, String]], map: { uid: :id }, keys: [:uid]) }
9
+ let(:data) { Hash[id: 1, name: 'Jane'] }
10
+ let(:model) { mock_model(:id, :name) }
11
+ let(:object) { model.new(data) }
12
+
13
+ context 'with public attribute readers' do
14
+ it 'returns dumped tuple' do
15
+ expect(dumper.call(object)).to eq([1, 'Jane'])
16
+ end
17
+ end
18
+
19
+ context 'with private attribute readers' do
20
+ before do
21
+ model.send(:private, :id)
22
+ model.send(:private, :name)
23
+ end
24
+
25
+ it 'returns dumped tuple' do
26
+ expect(dumper.call(object)).to eq([1, 'Jane'])
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Dumper, '#identity' do
6
+ subject(:dumper) { described_class.new(header) }
7
+
8
+ let(:header) { Mapper::Header.build([[:uid, Integer], [:name, String]], map: { uid: :id }, keys: [:uid]) }
9
+ let(:data) { Hash[id: 1, name: 'Jane'] }
10
+ let(:model) { mock_model(:id, :name) }
11
+ let(:object) { model.new(data) }
12
+
13
+ context 'with public attribute readers' do
14
+ it "returns object's identity" do
15
+ expect(dumper.identity(object)).to eq([1])
16
+ end
17
+ end
18
+
19
+ context 'with private attribute readers' do
20
+ before do
21
+ model.send(:private, :id)
22
+ end
23
+
24
+ it "returns object's identity" do
25
+ expect(dumper.identity(object)).to eq([1])
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Header, '#each' do
6
+ let(:object) { Mapper::Header.build(attributes) }
7
+ let(:attributes) { [[:id, Integer], [:name, String]] }
8
+ let(:id) { object[:id] }
9
+ let(:name) { object[:name] }
10
+
11
+ context 'with a block' do
12
+ subject { object.each { |attribute| result << attribute } }
13
+
14
+ let(:result) { [] }
15
+
16
+ it { should be(object) }
17
+
18
+ specify do
19
+ expect { subject }.to change { result }.from([]).to([id, name])
20
+ end
21
+ end
22
+
23
+ context 'without a block' do
24
+ subject { object.each }
25
+
26
+ it { should be_instance_of(Enumerator) }
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Header, '#[]' do
6
+ subject { object[name] }
7
+
8
+ let(:object) { Mapper::Header.build(attributes) }
9
+ let(:attributes) { [[:id, Integer]] }
10
+
11
+ context 'when attribute exists' do
12
+ let(:name) { :id }
13
+ let(:id) { Mapper::Attribute.coerce(attributes.first) }
14
+
15
+ it { should eql(id) }
16
+ end
17
+
18
+ context 'when attribute does not exist' do
19
+ let(:name) { :not_here }
20
+
21
+ specify do
22
+ expect { subject }.to raise_error(KeyError)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Header, '#keys' do
6
+ subject { object.keys }
7
+
8
+ let(:object) { Mapper::Header.build(attributes, options) }
9
+ let(:id) { object[:id] }
10
+ let(:name) { object[:name] }
11
+
12
+ context 'without mapping' do
13
+ let(:options) { Hash[keys: [:id]] }
14
+ let(:attributes) { [[:id, Integer], [:name, String]] }
15
+
16
+ it { should eql([id]) }
17
+ end
18
+
19
+ context 'with mapping' do
20
+ let(:attributes) { [[:user_id, Integer], [:name, String]] }
21
+ let(:options) { Hash[keys: [:user_id], map: { user_id: :id }] }
22
+
23
+ it { should eql([id]) }
24
+ end
25
+
26
+ context 'with multiple keys' do
27
+ let(:attributes) { [[:id, Integer], [:name, String]] }
28
+ let(:options) { Hash[keys: [:id, :name]] }
29
+
30
+ it { should eql([id, name]) }
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#identity_from_tuple' do
6
+ subject { mapper.identity_from_tuple(tuple) }
7
+
8
+ include_context 'Mapper'
9
+
10
+ before do
11
+ stub(loader).identity(tuple) { [1] }
12
+ end
13
+
14
+ it { should eq([1]) }
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#identity' do
6
+ subject { mapper.identity(object) }
7
+
8
+ include_context 'Mapper'
9
+
10
+ before do
11
+ stub(dumper).identity(object) { [1] }
12
+ end
13
+
14
+ it { should eq([1]) }
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#load' do
6
+ include_context 'Mapper'
7
+
8
+ it 'loads the tuple into model' do
9
+ stub(loader).call(tuple) { object }
10
+
11
+ expect(mapper.load(tuple)).to be(object)
12
+
13
+ loader.should have_received.call(tuple)
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::Allocator, '#call' do
6
+ it_behaves_like 'Mapper::Loader#call'
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::Allocator, '#identity' do
6
+ it_behaves_like 'Mapper::Loader#identity'
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::AttributeWriter, '#call' do
6
+ it_behaves_like 'Mapper::Loader#call'
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::AttributeWriter, '#identity' do
6
+ it_behaves_like 'Mapper::Loader#identity'
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::ObjectBuilder, '#call' do
6
+ it_behaves_like 'Mapper::Loader#call'
7
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper::Loader::ObjectBuilder, '#identity' do
6
+ it_behaves_like 'Mapper::Loader#identity'
7
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#model' do
6
+ subject { mapper.model }
7
+
8
+ include_context 'Mapper'
9
+
10
+ it { should be(model) }
11
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Mapper, '#new_object' do
6
+ subject { mapper.new_object(name: 'Jane', &block) }
7
+
8
+ include_context 'Mapper'
9
+
10
+ let(:attributes) { Hash[id: 1, name: 'Jane'] }
11
+ let(:block) { proc { self.id = 1 } }
12
+
13
+ it { should eql(model.new(attributes)) }
14
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rom-mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Piotr Solnica
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: concord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: equalizer
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: descendants_tracker
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: abstract_type
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.6
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.0.6
78
+ - !ruby/object:Gem::Dependency
79
+ name: adamantium
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.1'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.1'
94
+ description: rom-mapper
95
+ email: piotr.solnica@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - .gitignore
101
+ - .rspec
102
+ - .ruby-gemset
103
+ - .ruby-version
104
+ - .travis.yml
105
+ - Gemfile
106
+ - Gemfile.devtools
107
+ - Guardfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - config/devtools.yml
112
+ - config/flay.yml
113
+ - config/flog.yml
114
+ - config/mutant.yml
115
+ - config/reek.yml
116
+ - config/rubocop.yml
117
+ - lib/rom-mapper.rb
118
+ - lib/rom/mapper.rb
119
+ - lib/rom/mapper/attribute.rb
120
+ - lib/rom/mapper/dumper.rb
121
+ - lib/rom/mapper/header.rb
122
+ - lib/rom/mapper/loader.rb
123
+ - lib/rom/mapper/loader/allocator.rb
124
+ - lib/rom/mapper/loader/attribute_writer.rb
125
+ - lib/rom/mapper/loader/object_builder.rb
126
+ - lib/rom/version.rb
127
+ - rom-mapper.gemspec
128
+ - spec/shared/unit/loader_call.rb
129
+ - spec/shared/unit/loader_identity.rb
130
+ - spec/shared/unit/mapper_context.rb
131
+ - spec/spec_helper.rb
132
+ - spec/unit/rom/mapper/call_spec.rb
133
+ - spec/unit/rom/mapper/class_methods/build_spec.rb
134
+ - spec/unit/rom/mapper/dump_spec.rb
135
+ - spec/unit/rom/mapper/dumper/call_spec.rb
136
+ - spec/unit/rom/mapper/dumper/identity_spec.rb
137
+ - spec/unit/rom/mapper/header/each_spec.rb
138
+ - spec/unit/rom/mapper/header/element_reader_spec.rb
139
+ - spec/unit/rom/mapper/header/keys_spec.rb
140
+ - spec/unit/rom/mapper/identity_from_tuple_spec.rb
141
+ - spec/unit/rom/mapper/identity_spec.rb
142
+ - spec/unit/rom/mapper/load_spec.rb
143
+ - spec/unit/rom/mapper/loader/allocator/call_spec.rb
144
+ - spec/unit/rom/mapper/loader/allocator/identity_spec.rb
145
+ - spec/unit/rom/mapper/loader/attribute_writer/call_spec.rb
146
+ - spec/unit/rom/mapper/loader/attribute_writer/identity_spec.rb
147
+ - spec/unit/rom/mapper/loader/object_builder/call_spec.rb
148
+ - spec/unit/rom/mapper/loader/object_builder/identity_spec.rb
149
+ - spec/unit/rom/mapper/model_spec.rb
150
+ - spec/unit/rom/mapper/new_object_spec.rb
151
+ homepage: http://rom-rb.org
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.23
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: rom-mapper
176
+ test_files: []
177
+ has_rdoc: