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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22cd77ab1a0e834086636f81a34fcb75f478888443aecf3981373711f1b548e4
4
- data.tar.gz: 9a7192effd457c250e869b1d954d3dde62661601f4d9869521a83e35f3936811
3
+ metadata.gz: 12b984e8882e2b0701f33ed7b7d906f0a92ce8e5393599e48faf97ffede6010f
4
+ data.tar.gz: 560e9607957ac6099f11b00361d62e0b71086a4fbae82f0b41cbd18db830da4f
5
5
  SHA512:
6
- metadata.gz: c6e2618fcfab0987ebfca06da11ef83c0e5a1d0506facf18abbd892b14ebf7cf9151a8cf9fb65458909320046ae0490478285ab9c3cc7babc0aa4bacb027d2a7
7
- data.tar.gz: a9df678dc56e35366db45796e72f50ca003b72213083e110cc8f7b5a87be84979f8c4739d6aa161becd45e2560d11a66bc0a8044d18cf9207bfbd4fb58739346
6
+ metadata.gz: b7250d01edf599791ac6383e3c9ab40f41f7fc343edf8e002490bf33552bd9597cea3a24896741d9a5f1fd1b84a1b3bad684b6246557d1d890c54fbe7e8e2b64
7
+ data.tar.gz: bf2df36a73419a74bf07afccc4c1743f40e87533924942f8bf1af89513d0a59d968e678d7d2cc5eb6b7793ec685e19b7addc6a2e24ff3adbbc38d45cac106dc6
@@ -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
@@ -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
@@ -87,7 +87,7 @@ module ROM
87
87
  class PluginRegistryBase < Registry
88
88
  include Dry::Equalizer(:elements, :plugin_type)
89
89
 
90
- # !@attribute [r] plugin_type
90
+ # @!attribute [r] plugin_type
91
91
  # @return [Class] Typically ROM::PluginBase or its descendant
92
92
  option :plugin_type
93
93
 
@@ -217,7 +217,7 @@ module ROM
217
217
  def each
218
218
  return to_enum unless block_given?
219
219
 
220
- if auto_struct?
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 the wrapped relation with other mappers available in the registry
499
+ # Maps relation with custom mappers available in the registry
500
500
  #
501
- # @overload map_with(model)
502
- # Map tuples to the provided custom model class
503
- #
504
- # @example
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 auto-mapping and custom registered mappers
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] A new relation proxy with pipelined 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 instance of the provided class
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::Composite]
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
- # !@attribute [r] relation_name
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)
@@ -51,7 +51,7 @@ module ROM
51
51
  #
52
52
  # @api public
53
53
  def call(*args)
54
- left = root.with(auto_struct: false).call(*args)
54
+ left = root.with(auto_map: false, auto_struct: false).call(*args)
55
55
 
56
56
  right =
57
57
  if left.empty?
@@ -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 = commands.key?(type) ? commands[type] : commands[type, adapter, to_ast, use, plugins_options, opts]
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 mappers.any? && !base_command.is_a?(CommandProxy)
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
@@ -29,6 +29,13 @@ module ROM
29
29
  end
30
30
  alias_method :[], :call
31
31
 
32
+ # @see Relation#map_to
33
+ #
34
+ # @api public
35
+ def map_to(klass)
36
+ self >> left.map_to(klass).mapper
37
+ end
38
+
32
39
  private
33
40
 
34
41
  # @api private
@@ -59,11 +59,11 @@ module ROM
59
59
  #
60
60
  # @see Relation#map_with
61
61
  #
62
- # @return [Graph]
62
+ # @return [Relation::Composite]
63
63
  #
64
64
  # @api public
65
- def map_with(*args)
66
- self.class.new(root.map_with(*args), nodes)
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
@@ -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
@@ -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 uncludes attributes from other relations etc.
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
  #
@@ -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
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module Core
3
- VERSION = '4.1.2'.freeze
3
+ VERSION = '4.2.0'.freeze
4
4
  end
5
5
  end
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.1.2
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-02-03 00:00:00.000000000 Z
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.3
307
+ rubygems_version: 2.7.4
308
308
  signing_key:
309
309
  specification_version: 4
310
310
  summary: Ruby Object Mapper