datamappify 0.53.2 → 0.60.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +27 -9
- data/lib/datamappify.rb +1 -0
- data/lib/datamappify/config.rb +18 -0
- data/lib/datamappify/data/criteria/common.rb +8 -1
- data/lib/datamappify/data/criteria/relational/concerns/set_criteria.rb +17 -4
- data/lib/datamappify/data/criteria/relational/find_by_key.rb +0 -7
- data/lib/datamappify/data/criteria/relational/save_by_key.rb +0 -6
- data/lib/datamappify/data/mapper.rb +14 -6
- data/lib/datamappify/data/mapper/attribute.rb +4 -9
- data/lib/datamappify/entity/inspectable.rb +0 -1
- data/lib/datamappify/repository.rb +3 -0
- data/lib/datamappify/repository/mapping_dsl.rb +16 -2
- data/lib/datamappify/repository/query_methods.rb +10 -6
- data/lib/datamappify/repository/unit_of_work/transaction.rb +0 -1
- data/lib/datamappify/version.rb +1 -1
- data/spec/config_spec.rb +14 -0
- data/spec/entity_spec.rb +0 -1
- data/spec/lazy_spec.rb +0 -1
- data/spec/repository/finders_spec.rb +10 -7
- data/spec/repository/reverse_mapped_spec.rb +5 -5
- data/spec/support/entities/reversed/author.rb +8 -0
- data/spec/support/entities/{post.rb → reversed/post.rb} +2 -2
- data/spec/support/repositories/active_record/computer_repository.rb +9 -9
- data/spec/support/repositories/active_record/reversed/author_repository.rb +8 -0
- data/spec/support/repositories/active_record/reversed/post_repository.rb +13 -0
- data/spec/support/repositories/active_record/user_repository.rb +4 -4
- data/spec/support/repositories/callbacks_chaining_repository.rb +9 -9
- data/spec/support/repositories/hero_user_repository.rb +6 -3
- data/spec/support/repositories/sequel/computer_repository.rb +9 -9
- data/spec/support/repositories/sequel/reversed/author_repository.rb +8 -0
- data/spec/support/repositories/sequel/reversed/post_repository.rb +13 -0
- data/spec/support/repositories/sequel/user_repository.rb +4 -4
- data/spec/support/tables/active_record.rb +2 -3
- data/spec/support/tables/sequel.rb +2 -3
- metadata +17 -14
- data/spec/support/entities/author.rb +0 -6
- data/spec/support/repositories/active_record/author_repository.rb +0 -6
- data/spec/support/repositories/active_record/post_repository.rb +0 -9
- data/spec/support/repositories/sequel/author_repository.rb +0 -6
- data/spec/support/repositories/sequel/post_repository.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7fa8132e32a3dec1dd746263e0df0eff57b5448
|
4
|
+
data.tar.gz: 7536658c8651e4f89cb6ff9021dcfe7107bc59ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51787e716646495a2ccff4474e783805ad8e81d1a1de59f3600c0b2b9a3a89e509eb56016fd0f9728ee8310a14fb8fbde2e72f28b9346c193a8a7a2247b6716c
|
7
|
+
data.tar.gz: 421115bd3c70db49fefe9a136ba9caedce4357d6e921e37c53533d350481a6f71e8304346c77389171451b6930ff01c4a6b998cb0fb24f0afa08c61363bee866
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## master
|
2
2
|
|
3
|
+
## 0.60.0 [2013-07-23]
|
4
|
+
|
5
|
+
- New API: Introduced `Datamappify.config` for configuring default behaviours.
|
6
|
+
- API change: `where` now replaces `find` for multiple items.
|
7
|
+
- API change: `map_attribute` now takes `:to` and `:provider` instead of a string for specifying data source.
|
8
|
+
- New API: Introduced `group` for grouping `map_attribute`.
|
9
|
+
- Added support for entity namespaces (closes #4).
|
10
|
+
|
3
11
|
## 0.53.2 [2013-07-18]
|
4
12
|
|
5
13
|
- Better attributes inspect. Thanks @jamesmoriarty!
|
data/README.md
CHANGED
@@ -175,6 +175,7 @@ class UserRepository
|
|
175
175
|
for_entity User
|
176
176
|
|
177
177
|
# specify the default data provider for unmapped attributes
|
178
|
+
# optionally you may use `Datamappify.config` to config this globally
|
178
179
|
default_provider :ActiveRecord
|
179
180
|
|
180
181
|
# specify any attributes that need to be mapped
|
@@ -185,11 +186,17 @@ class UserRepository
|
|
185
186
|
# - 'last_name' is mapped to the 'User' ActiveRecord class and its 'surname' attribute
|
186
187
|
# - 'driver_license' is mapped to the 'UserDriverLicense' ActiveRecord class and its 'number' attribute
|
187
188
|
# - 'passport' is mapped to the 'UserPassport' Sequel class and its 'number' attribute
|
188
|
-
# - attributes not specified here are mapped automatically to '
|
189
|
-
map_attribute :last_name, '
|
190
|
-
map_attribute :driver_license, '
|
191
|
-
map_attribute :passport, '
|
192
|
-
map_attribute :health_care, '
|
189
|
+
# - attributes not specified here are mapped automatically to 'User' with provider 'ActiveRecord'
|
190
|
+
map_attribute :last_name, :to => 'User#surname'
|
191
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
192
|
+
map_attribute :passport, :to => 'UserPassport#number', :provider => :Sequel
|
193
|
+
map_attribute :health_care, :to => 'UserHealthCare#number', :provider => :Sequel
|
194
|
+
|
195
|
+
# alternatively, you may group attribute mappings if they share certain options:
|
196
|
+
group :provider => :Sequel do
|
197
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
198
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
199
|
+
end
|
193
200
|
|
194
201
|
# attributes can also be reverse mapped by specifying the `via` option
|
195
202
|
#
|
@@ -197,7 +204,7 @@ class UserRepository
|
|
197
204
|
# and map `hobby_name` from the `name` attribute of `ActiveRecord::Hobby`
|
198
205
|
#
|
199
206
|
# this is useful for mapping form fields (similar to ActiveRecord's nested attributes)
|
200
|
-
map_attribute :hobby_name,
|
207
|
+
map_attribute :hobby_name, :to => 'Hobby#name', :via => :hobby_id
|
201
208
|
end
|
202
209
|
```
|
203
210
|
|
@@ -213,7 +220,7 @@ end
|
|
213
220
|
class GuestUserRepository < UserRepository
|
214
221
|
for_entity GuestUser
|
215
222
|
|
216
|
-
map_attribute :expiry, '
|
223
|
+
map_attribute :expiry, :to => 'User#expiry_date'
|
217
224
|
end
|
218
225
|
```
|
219
226
|
|
@@ -224,7 +231,7 @@ In the above example, both repositories deal with the `ActiveRecord::User` data
|
|
224
231
|
Datamappify repository by default creates the underlying data model classes for you. For example:
|
225
232
|
|
226
233
|
```ruby
|
227
|
-
map_attribute :driver_license, '
|
234
|
+
map_attribute :driver_license, :to => 'UserData::DriverLicense#number'
|
228
235
|
```
|
229
236
|
|
230
237
|
In the above example, a `Datamppify::Data::Record::ActiveRecord::UserDriverLicense` ActiveRecord model will be created. If you would like to customise the data model class, you may do so by creating one either under the default namespace or under the `Datamappify::Data::Record::NameOfDataProvider` namespace:
|
@@ -278,7 +285,7 @@ users = UserRepository.all
|
|
278
285
|
Returns an array of entities.
|
279
286
|
|
280
287
|
```ruby
|
281
|
-
users = UserRepository.
|
288
|
+
users = UserRepository.where(:first_name => 'Fred', :driver_license => 'AABBCCDD')
|
282
289
|
```
|
283
290
|
|
284
291
|
_Note: it does not currently support searching attributes from different data providers._
|
@@ -374,6 +381,16 @@ end
|
|
374
381
|
|
375
382
|
Note: Returning either `nil` or `false` from the callback will cancel all subsequent callbacks (and the action itself, if it's a `before_` callback).
|
376
383
|
|
384
|
+
### Default configuration
|
385
|
+
|
386
|
+
You may configure Datamappify's default behaviour. In Rails you would put it in an initializer file.
|
387
|
+
|
388
|
+
```ruby
|
389
|
+
Datamappify.config do |c|
|
390
|
+
c.default_provider = :ActiveRecord
|
391
|
+
end
|
392
|
+
```
|
393
|
+
|
377
394
|
## More Reading
|
378
395
|
|
379
396
|
You may check out this [article](http://fredwu.me/post/54009567748/) for more examples.
|
@@ -399,6 +416,7 @@ Refer to [CHANGELOG](CHANGELOG.md).
|
|
399
416
|
- [Fred Wu](http://fredwu.me/) - author.
|
400
417
|
- [James Ladd](http://jamesladdcode.com/) for reviewing the code and giving advice on architectural decisions.
|
401
418
|
- [Locomote](http://www.locomote.com.au/) - where Datamappify is built and being tested in product development.
|
419
|
+
- And with these [awesome contributors](https://github.com/fredwu/datamappify/contributors)!
|
402
420
|
|
403
421
|
## License
|
404
422
|
|
data/lib/datamappify.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Datamappify
|
2
|
+
Config = Struct.new(:default_provider)
|
3
|
+
|
4
|
+
# A Struct containing default configuration values
|
5
|
+
#
|
6
|
+
# @return [Config]
|
7
|
+
def self.defaults
|
8
|
+
@defaults ||= Config.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# @yield
|
12
|
+
# configuration block
|
13
|
+
#
|
14
|
+
# @return [void]
|
15
|
+
def self.config(&block)
|
16
|
+
block.call(defaults)
|
17
|
+
end
|
18
|
+
end
|
@@ -97,7 +97,14 @@ module Datamappify
|
|
97
97
|
#
|
98
98
|
# @return [Boolean]
|
99
99
|
def primary_record?
|
100
|
-
|
100
|
+
source_class_name == default_source_class_name
|
101
|
+
end
|
102
|
+
|
103
|
+
# Source class name with its namespace but without Data::Record::Provider
|
104
|
+
#
|
105
|
+
# @return [String]
|
106
|
+
def source_class_name
|
107
|
+
source_class.name.split('Datamappify::Data::Record::')[-1].split('::', 2)[-1]
|
101
108
|
end
|
102
109
|
|
103
110
|
# Ignores the current Criteria's operation if there is no dirty attributes
|
@@ -7,22 +7,35 @@ module Datamappify
|
|
7
7
|
def initialize(*args)
|
8
8
|
super
|
9
9
|
|
10
|
-
|
10
|
+
if entity.id
|
11
|
+
self.criteria = build_criteria
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
def
|
16
|
-
|
17
|
+
def build_criteria
|
18
|
+
if options[:via].nil?
|
19
|
+
criteria_for_normal_mapping
|
20
|
+
elsif finder?
|
17
21
|
criteria_for_reverse_mapping
|
18
22
|
else
|
19
|
-
|
23
|
+
{}
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
27
|
+
def criteria_for_reverse_mapping
|
28
|
+
reverse_id = options[:primary_record].send(options[:via])
|
29
|
+
reverse_id ? { :id => reverse_id } : {}
|
30
|
+
end
|
31
|
+
|
23
32
|
def criteria_for_normal_mapping
|
24
33
|
{ key_name => entity.id }
|
25
34
|
end
|
35
|
+
|
36
|
+
def finder?
|
37
|
+
self.class.name =~ /Find/
|
38
|
+
end
|
26
39
|
end
|
27
40
|
end
|
28
41
|
end
|
@@ -11,13 +11,6 @@ module Datamappify
|
|
11
11
|
def initialize(source_class, entity, attributes, options = {}, &block)
|
12
12
|
super(source_class, entity, nil, attributes, options, &block)
|
13
13
|
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def criteria_for_reverse_mapping
|
18
|
-
reverse_id = options[:primary_record].send(options[:via])
|
19
|
-
reverse_id ? { :id => reverse_id } : {}
|
20
|
-
end
|
21
14
|
end
|
22
15
|
end
|
23
16
|
end
|
@@ -20,6 +20,8 @@ module Datamappify
|
|
20
20
|
def initialize
|
21
21
|
@custom_mapping = {}
|
22
22
|
@custom_attribute_names = []
|
23
|
+
|
24
|
+
@default_provider_name = Datamappify.defaults.default_provider
|
23
25
|
end
|
24
26
|
|
25
27
|
# @return [Module]
|
@@ -78,26 +80,32 @@ module Datamappify
|
|
78
80
|
# @return [Array<Attribute>]
|
79
81
|
def default_attributes
|
80
82
|
@default_attributes ||= default_attribute_names.collect do |attribute|
|
81
|
-
Attribute.new(
|
83
|
+
Attribute.new(
|
84
|
+
attribute,
|
85
|
+
:to => default_source_for(attribute),
|
86
|
+
:provider => default_provider_name,
|
87
|
+
:primary_source_class => default_source_class
|
88
|
+
)
|
82
89
|
end
|
83
90
|
end
|
84
91
|
|
85
92
|
# @return [Array<Attribute>]
|
86
93
|
def custom_attributes
|
87
|
-
@custom_attributes ||= custom_mapping.collect do |attribute,
|
88
|
-
map_custom_attribute(attribute,
|
94
|
+
@custom_attributes ||= custom_mapping.collect do |attribute, options|
|
95
|
+
map_custom_attribute(attribute, options)
|
89
96
|
end
|
90
97
|
end
|
91
98
|
|
92
99
|
# @param (see Data::Mapper::Attribute#initialize)
|
93
100
|
#
|
94
101
|
# @return [Attribute]
|
95
|
-
def map_custom_attribute(name,
|
102
|
+
def map_custom_attribute(name, options)
|
96
103
|
@custom_attribute_names << name
|
97
104
|
|
105
|
+
options.reverse_merge!(:provider => default_provider_name)
|
98
106
|
options.merge!(:primary_source_class => default_source_class)
|
99
107
|
|
100
|
-
Attribute.new(name,
|
108
|
+
Attribute.new(name, options)
|
101
109
|
end
|
102
110
|
|
103
111
|
# @param attribute [Symbol]
|
@@ -105,7 +113,7 @@ module Datamappify
|
|
105
113
|
#
|
106
114
|
# @return [String]
|
107
115
|
def default_source_for(attribute)
|
108
|
-
"#{
|
116
|
+
"#{default_source_class_name}##{attribute}"
|
109
117
|
end
|
110
118
|
end
|
111
119
|
end
|
@@ -32,18 +32,15 @@ module Datamappify
|
|
32
32
|
# @param name [Symbol]
|
33
33
|
# name of the attribute
|
34
34
|
#
|
35
|
-
# @param source [String]
|
36
|
-
# data provider, class and attribute,
|
37
|
-
# e.g. "ActiveRecord::User#surname"
|
38
|
-
#
|
39
35
|
# @param options [Hash]
|
40
|
-
def initialize(name,
|
36
|
+
def initialize(name, options)
|
41
37
|
@key = name
|
42
38
|
@name = name.to_s
|
43
39
|
@options = options
|
40
|
+
@provider_name = options[:provider].to_s
|
44
41
|
@primary_source_class = options[:primary_source_class]
|
45
42
|
|
46
|
-
@
|
43
|
+
@source_class_name, @source_attribute_name = parse_source(options[:to])
|
47
44
|
|
48
45
|
if secondary_attribute?
|
49
46
|
if reverse_mapped?
|
@@ -151,9 +148,7 @@ module Datamappify
|
|
151
148
|
# @return [Array<String>]
|
152
149
|
# an array with provider name, source class name and source attribute name
|
153
150
|
def parse_source(source)
|
154
|
-
|
155
|
-
|
156
|
-
[provider_name, *source_class_and_attribute.split('#')]
|
151
|
+
source.split('#')
|
157
152
|
end
|
158
153
|
end
|
159
154
|
end
|
@@ -26,8 +26,22 @@ module Datamappify
|
|
26
26
|
# @param (see Data::Mapper::Attribute#initialize)
|
27
27
|
#
|
28
28
|
# @return [void]
|
29
|
-
def map_attribute(name,
|
30
|
-
data_mapper.custom_mapping[name] =
|
29
|
+
def map_attribute(name, options = {})
|
30
|
+
data_mapper.custom_mapping[name.to_sym] = self.current_group_options.merge(options)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param options [Hash]
|
34
|
+
#
|
35
|
+
# @yield
|
36
|
+
# a block containing `map_attribute` DSLs
|
37
|
+
#
|
38
|
+
# @return [void]
|
39
|
+
def group(options = {}, &block)
|
40
|
+
self.current_group_options = options
|
41
|
+
|
42
|
+
block.call
|
43
|
+
|
44
|
+
self.current_group_options = {}
|
31
45
|
end
|
32
46
|
end
|
33
47
|
end
|
@@ -20,16 +20,20 @@ module Datamappify
|
|
20
20
|
QueryMethod::Exists.new(query_options, entity).perform
|
21
21
|
end
|
22
22
|
|
23
|
-
# @param criteria [Integer,
|
23
|
+
# @param criteria [Integer, String]
|
24
24
|
# an entity id or a hash containing criteria
|
25
25
|
#
|
26
26
|
# @return [Entity, nil]
|
27
27
|
def find(criteria)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
QueryMethod::Find.new(query_options, criteria).perform
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param criteria [Hash]
|
32
|
+
# a hash containing criteria
|
33
|
+
#
|
34
|
+
# @return [Entity]
|
35
|
+
def where(criteria)
|
36
|
+
QueryMethod::FindMultiple.new(query_options, criteria).perform
|
33
37
|
end
|
34
38
|
|
35
39
|
# Returns a collection of all the entities in the repository
|
data/lib/datamappify/version.rb
CHANGED
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Datamappify do
|
4
|
+
before do
|
5
|
+
Datamappify.config do |c|
|
6
|
+
c.default_provider = :ActiveRecord
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#default_provider" do
|
11
|
+
mapper = Datamappify::Data::Mapper.new
|
12
|
+
mapper.default_provider_name.should == :ActiveRecord
|
13
|
+
end
|
14
|
+
end
|
data/spec/entity_spec.rb
CHANGED
data/spec/lazy_spec.rb
CHANGED
@@ -14,6 +14,9 @@ shared_examples_for "finders" do |data_provider|
|
|
14
14
|
its(:id) { should == existing_user.id }
|
15
15
|
end
|
16
16
|
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#where" do
|
17
20
|
describe "by criteria" do
|
18
21
|
before do
|
19
22
|
user_repository.save!(User.new(:first_name => 'Mary', :driver_license => 'IDONTCARE'))
|
@@ -26,13 +29,13 @@ shared_examples_for "finders" do |data_provider|
|
|
26
29
|
end
|
27
30
|
|
28
31
|
describe "by attribute that does not exist" do
|
29
|
-
let(:records) { user_repository.
|
32
|
+
let(:records) { user_repository.where(:blah => 'Bob') }
|
30
33
|
|
31
34
|
it { expect { records }.to raise_exception(Datamappify::Data::EntityAttributeInvalid) }
|
32
35
|
end
|
33
36
|
|
34
37
|
describe "by primary attribute" do
|
35
|
-
let(:records) { user_repository.
|
38
|
+
let(:records) { user_repository.where(:first_name => 'Bob') }
|
36
39
|
subject { records }
|
37
40
|
|
38
41
|
it { should have(3).users }
|
@@ -46,7 +49,7 @@ shared_examples_for "finders" do |data_provider|
|
|
46
49
|
end
|
47
50
|
|
48
51
|
describe "by secondary attribute" do
|
49
|
-
let(:records) { user_repository.
|
52
|
+
let(:records) { user_repository.where(:driver_license => 'NO_LICENSE') }
|
50
53
|
subject { records }
|
51
54
|
|
52
55
|
it { should have(2).user }
|
@@ -61,7 +64,7 @@ shared_examples_for "finders" do |data_provider|
|
|
61
64
|
|
62
65
|
describe "by primary and secondary attributes" do
|
63
66
|
context "example 1" do
|
64
|
-
let(:records) { user_repository.
|
67
|
+
let(:records) { user_repository.where(:first_name => 'Bob', :driver_license => 'NO_LICENSE') }
|
65
68
|
subject { records }
|
66
69
|
|
67
70
|
it { should have(1).user }
|
@@ -75,7 +78,7 @@ shared_examples_for "finders" do |data_provider|
|
|
75
78
|
end
|
76
79
|
|
77
80
|
context "example 2" do
|
78
|
-
let(:records) { user_repository.
|
81
|
+
let(:records) { user_repository.where(:first_name => 'Bob', :driver_license => 'IDONTCARE') }
|
79
82
|
subject { records }
|
80
83
|
|
81
84
|
it { should have(2).users }
|
@@ -89,13 +92,13 @@ shared_examples_for "finders" do |data_provider|
|
|
89
92
|
end
|
90
93
|
|
91
94
|
context "example 3" do
|
92
|
-
subject { user_repository.
|
95
|
+
subject { user_repository.where(:first_name => 'Nope', :driver_license => 'IDONTCARE') }
|
93
96
|
|
94
97
|
it { should be_empty }
|
95
98
|
end
|
96
99
|
|
97
100
|
context "example 4" do
|
98
|
-
subject { user_repository.
|
101
|
+
subject { user_repository.where(:first_name => 'Bob', :driver_license => 'NOPE') }
|
99
102
|
|
100
103
|
it { should be_empty }
|
101
104
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples_for "reverse mapped" do |data_provider|
|
4
|
-
let!(:author_repository) { "AuthorRepository#{data_provider}".constantize }
|
5
|
-
let!(:post_repository) { "PostRepository#{data_provider}".constantize }
|
6
|
-
let(:new_author) { Author.new(:name => 'George R. R. Martin', :bio => 'GoT') }
|
7
|
-
let(:new_post) { Post.new(:title => 'Hello world', :author_name => 'Fred Wu', :author_bio => 'x')}
|
8
|
-
let(:new_post_2) { Post.new(:title => 'Hello earth', :author_name => 'Sheldon Cooper', :author_bio => 'y')}
|
4
|
+
let!(:author_repository) { "Reversed::AuthorRepository#{data_provider}".constantize }
|
5
|
+
let!(:post_repository) { "Reversed::PostRepository#{data_provider}".constantize }
|
6
|
+
let(:new_author) { Reversed::Author.new(:name => 'George R. R. Martin', :bio => 'GoT') }
|
7
|
+
let(:new_post) { Reversed::Post.new(:title => 'Hello world', :author_name => 'Fred Wu', :author_bio => 'x')}
|
8
|
+
let(:new_post_2) { Reversed::Post.new(:title => 'Hello earth', :author_name => 'Sheldon Cooper', :author_bio => 'y')}
|
9
9
|
|
10
10
|
context "#{data_provider}" do
|
11
11
|
before do
|
@@ -8,13 +8,13 @@ class ComputerRepositoryActiveRecord
|
|
8
8
|
for_entity Computer
|
9
9
|
default_provider :ActiveRecord
|
10
10
|
|
11
|
-
map_attribute :cpu, '
|
12
|
-
map_attribute :ram, '
|
13
|
-
map_attribute :hdd, '
|
14
|
-
map_attribute :gfx, '
|
15
|
-
map_attribute :vendor, '
|
16
|
-
map_attribute :software_os, '
|
17
|
-
map_attribute :software_vendor, '
|
18
|
-
map_attribute :game_os, '
|
19
|
-
map_attribute :game_vendor, '
|
11
|
+
map_attribute :cpu, :to => 'ComputerComponent::Hardware#cpu'
|
12
|
+
map_attribute :ram, :to => 'ComputerComponent::Hardware#ram'
|
13
|
+
map_attribute :hdd, :to => 'ComputerComponent::Hardware#hdd'
|
14
|
+
map_attribute :gfx, :to => 'ComputerComponent::Hardware#gfx'
|
15
|
+
map_attribute :vendor, :to => 'ComputerComponent::Hardware#vendor'
|
16
|
+
map_attribute :software_os, :to => 'ComputerSoftware#os'
|
17
|
+
map_attribute :software_vendor, :to => 'ComputerSoftware#vendor'
|
18
|
+
map_attribute :game_os, :to => 'ComputerSoftware#os', :via => :game_id
|
19
|
+
map_attribute :game_vendor, :to => 'ComputerSoftware#vendor', :via => :game_id
|
20
20
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Reversed
|
2
|
+
class PostRepositoryActiveRecord
|
3
|
+
include Datamappify::Repository
|
4
|
+
|
5
|
+
for_entity Post
|
6
|
+
default_provider :ActiveRecord
|
7
|
+
|
8
|
+
group :provider => :ActiveRecord, :via => :author_id do
|
9
|
+
map_attribute :author_name, :to => 'Reversed::Author#name'
|
10
|
+
map_attribute :author_bio, :to => 'Reversed::Author#bio'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -4,8 +4,8 @@ class UserRepositoryActiveRecord
|
|
4
4
|
for_entity User
|
5
5
|
default_provider :ActiveRecord
|
6
6
|
|
7
|
-
map_attribute :last_name, '
|
8
|
-
map_attribute :driver_license, '
|
9
|
-
map_attribute :passport, '
|
10
|
-
map_attribute :health_care, '
|
7
|
+
map_attribute :last_name, :to => 'User#surname'
|
8
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
9
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
10
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
11
11
|
end
|
@@ -4,9 +4,9 @@ class CallbacksChainingRepository
|
|
4
4
|
for_entity HeroUser
|
5
5
|
default_provider :ActiveRecord
|
6
6
|
|
7
|
-
map_attribute :first_name, '
|
8
|
-
map_attribute :last_name, '
|
9
|
-
map_attribute :gender, '
|
7
|
+
map_attribute :first_name, :to => 'HeroUser#first_name'
|
8
|
+
map_attribute :last_name, :to => 'HeroUserLastName#last_name', :provider => :Sequel
|
9
|
+
map_attribute :gender, :to => 'HeroUserLastName#gender', :provider => :Sequel
|
10
10
|
|
11
11
|
before_save :before_save_1
|
12
12
|
before_save :before_save_2
|
@@ -39,9 +39,9 @@ class CallbacksChainingPauseBeforeRepository
|
|
39
39
|
for_entity HeroUser
|
40
40
|
default_provider :ActiveRecord
|
41
41
|
|
42
|
-
map_attribute :first_name, '
|
43
|
-
map_attribute :last_name, '
|
44
|
-
map_attribute :gender, '
|
42
|
+
map_attribute :first_name, :to => 'HeroUser#first_name'
|
43
|
+
map_attribute :last_name, :to => 'HeroUserLastName#last_name', :provider => :Sequel
|
44
|
+
map_attribute :gender, :to => 'HeroUserLastName#gender', :provider => :Sequel
|
45
45
|
|
46
46
|
before_save :before_save_1
|
47
47
|
before_save :before_save_2
|
@@ -74,9 +74,9 @@ class CallbacksChainingPauseAfterRepository
|
|
74
74
|
for_entity HeroUser
|
75
75
|
default_provider :ActiveRecord
|
76
76
|
|
77
|
-
map_attribute :first_name, '
|
78
|
-
map_attribute :last_name, '
|
79
|
-
map_attribute :gender, '
|
77
|
+
map_attribute :first_name, :to => 'HeroUser#first_name'
|
78
|
+
map_attribute :last_name, :to => 'HeroUserLastName#last_name', :provider => :Sequel
|
79
|
+
map_attribute :gender, :to => 'HeroUserLastName#gender', :provider => :Sequel
|
80
80
|
|
81
81
|
before_save :before_save_1
|
82
82
|
before_save :before_save_2
|
@@ -4,9 +4,12 @@ class HeroUserRepository
|
|
4
4
|
for_entity HeroUser
|
5
5
|
default_provider :ActiveRecord
|
6
6
|
|
7
|
-
map_attribute :first_name, '
|
8
|
-
|
9
|
-
|
7
|
+
map_attribute :first_name, :to => 'HeroUser#first_name'
|
8
|
+
|
9
|
+
group :provider => :Sequel do
|
10
|
+
map_attribute :last_name, :to => 'HeroUserLastName#last_name'
|
11
|
+
map_attribute :gender, :to => 'HeroUserLastName#gender'
|
12
|
+
end
|
10
13
|
|
11
14
|
before_create :action_before_create
|
12
15
|
before_create :action_before_create_2
|
@@ -4,13 +4,13 @@ class ComputerRepositorySequel
|
|
4
4
|
for_entity Computer
|
5
5
|
default_provider :Sequel
|
6
6
|
|
7
|
-
map_attribute :cpu, '
|
8
|
-
map_attribute :ram, '
|
9
|
-
map_attribute :hdd, '
|
10
|
-
map_attribute :gfx, '
|
11
|
-
map_attribute :vendor, '
|
12
|
-
map_attribute :software_os, '
|
13
|
-
map_attribute :software_vendor, '
|
14
|
-
map_attribute :game_os, '
|
15
|
-
map_attribute :game_vendor, '
|
7
|
+
map_attribute :cpu, :to => 'ComputerComponent::Hardware#cpu'
|
8
|
+
map_attribute :ram, :to => 'ComputerComponent::Hardware#ram'
|
9
|
+
map_attribute :hdd, :to => 'ComputerComponent::Hardware#hdd'
|
10
|
+
map_attribute :gfx, :to => 'ComputerComponent::Hardware#gfx'
|
11
|
+
map_attribute :vendor, :to => 'ComputerComponent::Hardware#vendor'
|
12
|
+
map_attribute :software_os, :to => 'ComputerComponent::Software#os'
|
13
|
+
map_attribute :software_vendor, :to => 'ComputerComponent::Software#vendor'
|
14
|
+
map_attribute :game_os, :to => 'ComputerComponent::Software#os', :via => :game_id
|
15
|
+
map_attribute :game_vendor, :to => 'ComputerComponent::Software#vendor', :via => :game_id
|
16
16
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Reversed
|
2
|
+
class PostRepositorySequel
|
3
|
+
include Datamappify::Repository
|
4
|
+
|
5
|
+
for_entity Post
|
6
|
+
default_provider :Sequel
|
7
|
+
|
8
|
+
group :provider => :Sequel, :via => :author_id do
|
9
|
+
map_attribute :author_name, :to => 'Reversed::Author#name'
|
10
|
+
map_attribute :author_bio, :to => 'Reversed::Author#bio'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -4,8 +4,8 @@ class UserRepositorySequel
|
|
4
4
|
for_entity User
|
5
5
|
default_provider :Sequel
|
6
6
|
|
7
|
-
map_attribute :last_name, '
|
8
|
-
map_attribute :driver_license, '
|
9
|
-
map_attribute :passport, '
|
10
|
-
map_attribute :health_care, '
|
7
|
+
map_attribute :last_name, :to => 'User#surname'
|
8
|
+
map_attribute :driver_license, :to => 'UserDriverLicense#number'
|
9
|
+
map_attribute :passport, :to => 'UserPassport#number'
|
10
|
+
map_attribute :health_care, :to => 'UserHealthCare#number'
|
11
11
|
end
|
@@ -64,16 +64,15 @@ ActiveRecord::Migration.suppress_messages do
|
|
64
64
|
t.timestamps
|
65
65
|
end
|
66
66
|
|
67
|
-
create_table :
|
67
|
+
create_table :reversed_posts do |t|
|
68
68
|
t.string :title
|
69
69
|
t.references :author
|
70
70
|
t.timestamps
|
71
71
|
end
|
72
72
|
|
73
|
-
create_table :
|
73
|
+
create_table :reversed_authors do |t|
|
74
74
|
t.string :name
|
75
75
|
t.string :bio
|
76
|
-
t.references :post
|
77
76
|
t.timestamps
|
78
77
|
end
|
79
78
|
|
@@ -77,7 +77,7 @@ DB.create_table :user_health_cares do
|
|
77
77
|
DateTime :updated_at
|
78
78
|
end
|
79
79
|
|
80
|
-
DB.create_table :
|
80
|
+
DB.create_table :reversed_posts do |t|
|
81
81
|
primary_key :id
|
82
82
|
String :title
|
83
83
|
foreign_key :author_id
|
@@ -85,11 +85,10 @@ DB.create_table :posts do |t|
|
|
85
85
|
DateTime :updated_at
|
86
86
|
end
|
87
87
|
|
88
|
-
DB.create_table :
|
88
|
+
DB.create_table :reversed_authors do |t|
|
89
89
|
primary_key :id
|
90
90
|
String :name
|
91
91
|
String :bio
|
92
|
-
foreign_key :post_id
|
93
92
|
DateTime :created_at
|
94
93
|
DateTime :updated_at
|
95
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datamappify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.60.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -270,6 +270,7 @@ files:
|
|
270
270
|
- Rakefile
|
271
271
|
- datamappify.gemspec
|
272
272
|
- lib/datamappify.rb
|
273
|
+
- lib/datamappify/config.rb
|
273
274
|
- lib/datamappify/data.rb
|
274
275
|
- lib/datamappify/data/criteria.rb
|
275
276
|
- lib/datamappify/data/criteria/active_record/count.rb
|
@@ -341,6 +342,7 @@ files:
|
|
341
342
|
- lib/datamappify/repository/unit_of_work/persistent_states/object.rb
|
342
343
|
- lib/datamappify/repository/unit_of_work/transaction.rb
|
343
344
|
- lib/datamappify/version.rb
|
345
|
+
- spec/config_spec.rb
|
344
346
|
- spec/entity/composable_spec.rb
|
345
347
|
- spec/entity/inheritance_spec.rb
|
346
348
|
- spec/entity/relation_spec.rb
|
@@ -358,33 +360,33 @@ files:
|
|
358
360
|
- spec/repository_spec.rb
|
359
361
|
- spec/spec_helper.rb
|
360
362
|
- spec/support/entities/admin_user.rb
|
361
|
-
- spec/support/entities/author.rb
|
362
363
|
- spec/support/entities/comment.rb
|
363
364
|
- spec/support/entities/computer.rb
|
364
365
|
- spec/support/entities/computer_component/hardware.rb
|
365
366
|
- spec/support/entities/computer_component/software.rb
|
366
367
|
- spec/support/entities/group.rb
|
367
368
|
- spec/support/entities/hero_user.rb
|
368
|
-
- spec/support/entities/
|
369
|
+
- spec/support/entities/reversed/author.rb
|
370
|
+
- spec/support/entities/reversed/post.rb
|
369
371
|
- spec/support/entities/role.rb
|
370
372
|
- spec/support/entities/user.rb
|
371
373
|
- spec/support/monkey_patches/database_cleaner.rb
|
372
374
|
- spec/support/repositories/active_record/admin_user_repository.rb
|
373
|
-
- spec/support/repositories/active_record/author_repository.rb
|
374
375
|
- spec/support/repositories/active_record/comment_repository.rb
|
375
376
|
- spec/support/repositories/active_record/computer_repository.rb
|
376
377
|
- spec/support/repositories/active_record/group_repository.rb
|
377
|
-
- spec/support/repositories/active_record/
|
378
|
+
- spec/support/repositories/active_record/reversed/author_repository.rb
|
379
|
+
- spec/support/repositories/active_record/reversed/post_repository.rb
|
378
380
|
- spec/support/repositories/active_record/role_repository.rb
|
379
381
|
- spec/support/repositories/active_record/user_repository.rb
|
380
382
|
- spec/support/repositories/callbacks_chaining_repository.rb
|
381
383
|
- spec/support/repositories/hero_user_repository.rb
|
382
384
|
- spec/support/repositories/sequel/admin_user_repository.rb
|
383
|
-
- spec/support/repositories/sequel/author_repository.rb
|
384
385
|
- spec/support/repositories/sequel/comment_repository.rb
|
385
386
|
- spec/support/repositories/sequel/computer_repository.rb
|
386
387
|
- spec/support/repositories/sequel/group_repository.rb
|
387
|
-
- spec/support/repositories/sequel/
|
388
|
+
- spec/support/repositories/sequel/reversed/author_repository.rb
|
389
|
+
- spec/support/repositories/sequel/reversed/post_repository.rb
|
388
390
|
- spec/support/repositories/sequel/role_repository.rb
|
389
391
|
- spec/support/repositories/sequel/user_repository.rb
|
390
392
|
- spec/support/shared/contexts.rb
|
@@ -419,6 +421,7 @@ specification_version: 4
|
|
419
421
|
summary: Compose, decouple and manage domain logic and data persistence separately.
|
420
422
|
Works particularly great for composing form objects!
|
421
423
|
test_files:
|
424
|
+
- spec/config_spec.rb
|
422
425
|
- spec/entity/composable_spec.rb
|
423
426
|
- spec/entity/inheritance_spec.rb
|
424
427
|
- spec/entity/relation_spec.rb
|
@@ -436,33 +439,33 @@ test_files:
|
|
436
439
|
- spec/repository_spec.rb
|
437
440
|
- spec/spec_helper.rb
|
438
441
|
- spec/support/entities/admin_user.rb
|
439
|
-
- spec/support/entities/author.rb
|
440
442
|
- spec/support/entities/comment.rb
|
441
443
|
- spec/support/entities/computer.rb
|
442
444
|
- spec/support/entities/computer_component/hardware.rb
|
443
445
|
- spec/support/entities/computer_component/software.rb
|
444
446
|
- spec/support/entities/group.rb
|
445
447
|
- spec/support/entities/hero_user.rb
|
446
|
-
- spec/support/entities/
|
448
|
+
- spec/support/entities/reversed/author.rb
|
449
|
+
- spec/support/entities/reversed/post.rb
|
447
450
|
- spec/support/entities/role.rb
|
448
451
|
- spec/support/entities/user.rb
|
449
452
|
- spec/support/monkey_patches/database_cleaner.rb
|
450
453
|
- spec/support/repositories/active_record/admin_user_repository.rb
|
451
|
-
- spec/support/repositories/active_record/author_repository.rb
|
452
454
|
- spec/support/repositories/active_record/comment_repository.rb
|
453
455
|
- spec/support/repositories/active_record/computer_repository.rb
|
454
456
|
- spec/support/repositories/active_record/group_repository.rb
|
455
|
-
- spec/support/repositories/active_record/
|
457
|
+
- spec/support/repositories/active_record/reversed/author_repository.rb
|
458
|
+
- spec/support/repositories/active_record/reversed/post_repository.rb
|
456
459
|
- spec/support/repositories/active_record/role_repository.rb
|
457
460
|
- spec/support/repositories/active_record/user_repository.rb
|
458
461
|
- spec/support/repositories/callbacks_chaining_repository.rb
|
459
462
|
- spec/support/repositories/hero_user_repository.rb
|
460
463
|
- spec/support/repositories/sequel/admin_user_repository.rb
|
461
|
-
- spec/support/repositories/sequel/author_repository.rb
|
462
464
|
- spec/support/repositories/sequel/comment_repository.rb
|
463
465
|
- spec/support/repositories/sequel/computer_repository.rb
|
464
466
|
- spec/support/repositories/sequel/group_repository.rb
|
465
|
-
- spec/support/repositories/sequel/
|
467
|
+
- spec/support/repositories/sequel/reversed/author_repository.rb
|
468
|
+
- spec/support/repositories/sequel/reversed/post_repository.rb
|
466
469
|
- spec/support/repositories/sequel/role_repository.rb
|
467
470
|
- spec/support/repositories/sequel/user_repository.rb
|
468
471
|
- spec/support/shared/contexts.rb
|