rom-core 4.1.2 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/rom/memory/relation.rb +19 -0
- data/lib/rom/plugin_registry.rb +1 -1
- data/lib/rom/relation.rb +11 -19
- data/lib/rom/relation/class_interface.rb +1 -1
- data/lib/rom/relation/combined.rb +1 -1
- data/lib/rom/relation/commands.rb +7 -4
- data/lib/rom/relation/composite.rb +7 -0
- data/lib/rom/relation/graph.rb +3 -3
- data/lib/rom/relation/wrap.rb +1 -1
- data/lib/rom/schema.rb +1 -1
- data/lib/rom/schema/inferrer.rb +21 -0
- data/lib/rom/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b984e8882e2b0701f33ed7b7d906f0a92ce8e5393599e48faf97ffede6010f
|
4
|
+
data.tar.gz: 560e9607957ac6099f11b00361d62e0b71086a4fbae82f0b41cbd18db830da4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7250d01edf599791ac6383e3c9ab40f41f7fc343edf8e002490bf33552bd9597cea3a24896741d9a5f1fd1b84a1b3bad684b6246557d1d890c54fbe7e8e2b64
|
7
|
+
data.tar.gz: bf2df36a73419a74bf07afccc4c1743f40e87533924942f8bf1af89513d0a59d968e678d7d2cc5eb6b7793ec685e19b7addc6a2e24ff3adbbc38d45cac106dc6
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# v4.2.0 2018-03-29
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
* `Relation#map_with` applies auto-mapping prior custom mappers (solnic)
|
6
|
+
* `Relation#map_to` works along with `Relation#map_with` (solnic)
|
7
|
+
* `Relation#commands` no longers tries to map results through all custom registered mappers (solnic)
|
8
|
+
|
9
|
+
## Added
|
10
|
+
|
11
|
+
* Custom `MapperCompiler` subclass can provide mapper options via `mapper_options(...)` class attribute (solnic)
|
12
|
+
|
13
|
+
[Compare v4.1.2...v4.2.0](https://github.com/rom-rb/rom/compare/v4.1.2...v4.2.0)
|
14
|
+
|
1
15
|
# v4.1.2 2018-02-03
|
2
16
|
|
3
17
|
## Fixed
|
data/lib/rom/memory/relation.rb
CHANGED
@@ -17,6 +17,25 @@ module ROM
|
|
17
17
|
adapter :memory
|
18
18
|
schema_class Memory::Schema
|
19
19
|
|
20
|
+
# @!method take(amount)
|
21
|
+
# @param (see Dataset#take)
|
22
|
+
# @return [Relation]
|
23
|
+
# @see Dataset#take
|
24
|
+
#
|
25
|
+
# @!method join(*args)
|
26
|
+
# @param (see Dataset#take)
|
27
|
+
# @return [Relation]
|
28
|
+
# @see Dataset#join
|
29
|
+
#
|
30
|
+
# @!method restrict(criteria = nil)
|
31
|
+
# @param (see Dataset#restrict)
|
32
|
+
# @return [Relation]
|
33
|
+
# @see Dataset#restrict
|
34
|
+
#
|
35
|
+
# @!method order(*fields)
|
36
|
+
# @param (see Dataset#order)
|
37
|
+
# @return [Relation]
|
38
|
+
# @see Dataset#order
|
20
39
|
forward :take, :join, :restrict, :order
|
21
40
|
|
22
41
|
# Project a relation with provided attribute names
|
data/lib/rom/plugin_registry.rb
CHANGED
@@ -87,7 +87,7 @@ module ROM
|
|
87
87
|
class PluginRegistryBase < Registry
|
88
88
|
include Dry::Equalizer(:elements, :plugin_type)
|
89
89
|
|
90
|
-
#
|
90
|
+
# @!attribute [r] plugin_type
|
91
91
|
# @return [Class] Typically ROM::PluginBase or its descendant
|
92
92
|
option :plugin_type
|
93
93
|
|
data/lib/rom/relation.rb
CHANGED
@@ -217,7 +217,7 @@ module ROM
|
|
217
217
|
def each
|
218
218
|
return to_enum unless block_given?
|
219
219
|
|
220
|
-
if
|
220
|
+
if auto_map?
|
221
221
|
mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) }
|
222
222
|
else
|
223
223
|
dataset.each { |tuple| yield(output_schema[tuple]) }
|
@@ -496,15 +496,12 @@ module ROM
|
|
496
496
|
mappers[to_ast]
|
497
497
|
end
|
498
498
|
|
499
|
-
# Maps
|
499
|
+
# Maps relation with custom mappers available in the registry
|
500
500
|
#
|
501
|
-
#
|
502
|
-
#
|
503
|
-
#
|
504
|
-
#
|
505
|
-
# users.map_with(MyUserModel)
|
506
|
-
#
|
507
|
-
# @param [Class>] model Your custom model class
|
501
|
+
# When `auto_map` is enabled, your mappers will be applied after performing
|
502
|
+
# default auto-mapping. This means that you can compose complex relations
|
503
|
+
# and have them auto-mapped, and use much simpler custom mappers to adjust
|
504
|
+
# resulting data according to your requirements.
|
508
505
|
#
|
509
506
|
# @overload map_with(*mappers)
|
510
507
|
# Map tuples using registered mappers
|
@@ -515,37 +512,32 @@ module ROM
|
|
515
512
|
# @param [Array<Symbol>] mappers A list of mapper identifiers
|
516
513
|
#
|
517
514
|
# @overload map_with(*mappers, auto_map: true)
|
518
|
-
# Map tuples using
|
519
|
-
#
|
520
|
-
# If `auto_map` is enabled, your mappers will be applied after performing
|
521
|
-
# default auto-mapping. This means that you can compose complex relations
|
522
|
-
# and have them auto-mapped, and use much simpler custom mappers to adjust
|
523
|
-
# resulting data according to your requirements.
|
515
|
+
# Map tuples using custom registered mappers and enforce auto-mapping
|
524
516
|
#
|
525
517
|
# @example
|
526
518
|
# users.map_with(:my_mapper, :my_other_mapper, auto_map: true)
|
527
519
|
#
|
528
520
|
# @param [Array<Symbol>] mappers A list of mapper identifiers
|
529
521
|
#
|
530
|
-
# @return [Relation]
|
522
|
+
# @return [Relation::Composite] Mapped relation
|
531
523
|
#
|
532
524
|
# @api public
|
533
525
|
def map_with(*names, **opts)
|
534
526
|
super(*names).with(opts)
|
535
527
|
end
|
536
528
|
|
537
|
-
# Return a new relation that will map its tuples to
|
529
|
+
# Return a new relation that will map its tuples to instances of the provided class
|
538
530
|
#
|
539
531
|
# @example
|
540
532
|
# users.map_to(MyUserModel)
|
541
533
|
#
|
542
534
|
# @param [Class] klass Your custom model class
|
543
535
|
#
|
544
|
-
# @return [Relation
|
536
|
+
# @return [Relation]
|
545
537
|
#
|
546
538
|
# @api public
|
547
539
|
def map_to(klass, **opts)
|
548
|
-
with(opts.merge(auto_struct: true, meta: { model: klass }))
|
540
|
+
with(opts.merge(auto_map: false, auto_struct: true, meta: { model: klass }))
|
549
541
|
end
|
550
542
|
|
551
543
|
# Return a new relation with an aliased name
|
@@ -128,7 +128,7 @@ module ROM
|
|
128
128
|
# @api private
|
129
129
|
attr_reader :schema_proc
|
130
130
|
|
131
|
-
#
|
131
|
+
# @!attribute [r] relation_name
|
132
132
|
# @return [Name] Qualified relation name
|
133
133
|
def relation_name
|
134
134
|
raise MissingSchemaError.new(self) unless defined?(@relation_name)
|
@@ -36,14 +36,17 @@ module ROM
|
|
36
36
|
#
|
37
37
|
# @api public
|
38
38
|
def command(type, mapper: nil, use: EMPTY_ARRAY, plugins_options: EMPTY_HASH, **opts)
|
39
|
-
base_command =
|
39
|
+
base_command =
|
40
|
+
if commands.key?(type)
|
41
|
+
commands[type]
|
42
|
+
else
|
43
|
+
commands[type, adapter, to_ast, use, plugins_options, opts]
|
44
|
+
end
|
40
45
|
|
41
46
|
command =
|
42
47
|
if mapper
|
43
48
|
base_command >> mappers[mapper]
|
44
|
-
elsif
|
45
|
-
mappers.reduce(base_command) { |a, (_, e)| a >> e }
|
46
|
-
elsif auto_struct? || auto_map?
|
49
|
+
elsif auto_map?
|
47
50
|
base_command >> self.mapper
|
48
51
|
else
|
49
52
|
base_command
|
data/lib/rom/relation/graph.rb
CHANGED
@@ -59,11 +59,11 @@ module ROM
|
|
59
59
|
#
|
60
60
|
# @see Relation#map_with
|
61
61
|
#
|
62
|
-
# @return [
|
62
|
+
# @return [Relation::Composite]
|
63
63
|
#
|
64
64
|
# @api public
|
65
|
-
def map_with(*
|
66
|
-
self.class.new(root.
|
65
|
+
def map_with(*names, **opts)
|
66
|
+
names.reduce(self.class.new(root.with(opts), nodes)) { |a, e| a >> mappers[e] }
|
67
67
|
end
|
68
68
|
|
69
69
|
# Map graph tuples to custom objects
|
data/lib/rom/relation/wrap.rb
CHANGED
@@ -27,7 +27,7 @@ module ROM
|
|
27
27
|
# @api public
|
28
28
|
def call(*args)
|
29
29
|
if auto_map?
|
30
|
-
Loaded.new(self, mapper.(relation.with(auto_struct: false)))
|
30
|
+
Loaded.new(self, mapper.(relation.with(auto_map: false, auto_struct: false)))
|
31
31
|
else
|
32
32
|
Loaded.new(self, relation.(*args))
|
33
33
|
end
|
data/lib/rom/schema.rb
CHANGED
@@ -139,7 +139,7 @@ module ROM
|
|
139
139
|
#
|
140
140
|
# This can be used by views to generate a new relation automatically.
|
141
141
|
# In example a schema can project a relation, join any additional relations
|
142
|
-
# if it
|
142
|
+
# if it includes attributes from other relations etc.
|
143
143
|
#
|
144
144
|
# Default implementation is a no-op and it simply returns back untouched relation
|
145
145
|
#
|
data/lib/rom/schema/inferrer.rb
CHANGED
@@ -7,6 +7,21 @@ module ROM
|
|
7
7
|
extend Dry::Core::ClassAttributes
|
8
8
|
extend Initializer
|
9
9
|
|
10
|
+
# @!method self.attributes_inferrer
|
11
|
+
# @overload attributes_inferrer
|
12
|
+
# @return [Proc]
|
13
|
+
#
|
14
|
+
# @overload attributes_inferrer(value)
|
15
|
+
# @param value [Proc]
|
16
|
+
# @return [Proc]
|
17
|
+
#
|
18
|
+
# @!method self.attr_class
|
19
|
+
# @overload attr_class
|
20
|
+
# @return [Class(ROM::Attribute)]
|
21
|
+
#
|
22
|
+
# @overload attr_class(value)
|
23
|
+
# @param value [Class(ROM::Attribute)]
|
24
|
+
# @return [Class(ROM::Attribute)]
|
10
25
|
defines :attributes_inferrer, :attr_class
|
11
26
|
|
12
27
|
MissingAttributesError = Class.new(StandardError) do
|
@@ -26,12 +41,18 @@ module ROM
|
|
26
41
|
|
27
42
|
include Dry::Equalizer(:options)
|
28
43
|
|
44
|
+
# @!attribute [r] attr_class
|
45
|
+
# @return [Class(ROM::Attribute)]
|
29
46
|
option :attr_class, default: -> { self.class.attr_class }
|
30
47
|
|
48
|
+
# @!attribute [r] enabled
|
49
|
+
# @return [Boolean]
|
31
50
|
option :enabled, default: -> { true }
|
32
51
|
|
33
52
|
alias_method :enabled?, :enabled
|
34
53
|
|
54
|
+
# @!attribute [r] attributes_inferrer
|
55
|
+
# @return [ROM::Schema::AttributesInferrer]
|
35
56
|
option :attributes_inferrer, default: -> { self.class.attributes_inferrer }
|
36
57
|
|
37
58
|
# @api private
|
data/lib/rom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -304,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
304
304
|
version: '0'
|
305
305
|
requirements: []
|
306
306
|
rubyforge_project:
|
307
|
-
rubygems_version: 2.7.
|
307
|
+
rubygems_version: 2.7.4
|
308
308
|
signing_key:
|
309
309
|
specification_version: 4
|
310
310
|
summary: Ruby Object Mapper
|