rom-core 4.2.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/lib/rom-core.rb +2 -0
  4. data/lib/rom/array_dataset.rb +2 -0
  5. data/lib/rom/association_set.rb +2 -0
  6. data/lib/rom/associations/abstract.rb +2 -0
  7. data/lib/rom/associations/definitions.rb +2 -0
  8. data/lib/rom/associations/definitions/abstract.rb +2 -0
  9. data/lib/rom/associations/definitions/many_to_many.rb +2 -0
  10. data/lib/rom/associations/definitions/many_to_one.rb +2 -0
  11. data/lib/rom/associations/definitions/one_to_many.rb +2 -0
  12. data/lib/rom/associations/definitions/one_to_one.rb +2 -0
  13. data/lib/rom/associations/definitions/one_to_one_through.rb +2 -0
  14. data/lib/rom/associations/many_to_many.rb +2 -0
  15. data/lib/rom/associations/many_to_one.rb +2 -0
  16. data/lib/rom/associations/one_to_many.rb +2 -0
  17. data/lib/rom/associations/one_to_one.rb +2 -0
  18. data/lib/rom/associations/one_to_one_through.rb +2 -0
  19. data/lib/rom/associations/through_identifier.rb +2 -0
  20. data/lib/rom/attribute.rb +58 -72
  21. data/lib/rom/auto_curry.rb +2 -0
  22. data/lib/rom/cache.rb +2 -0
  23. data/lib/rom/command.rb +7 -5
  24. data/lib/rom/command_compiler.rb +2 -0
  25. data/lib/rom/command_proxy.rb +2 -0
  26. data/lib/rom/command_registry.rb +13 -7
  27. data/lib/rom/commands.rb +2 -0
  28. data/lib/rom/commands/class_interface.rb +4 -2
  29. data/lib/rom/commands/composite.rb +2 -0
  30. data/lib/rom/commands/create.rb +2 -0
  31. data/lib/rom/commands/delete.rb +2 -0
  32. data/lib/rom/commands/graph.rb +2 -0
  33. data/lib/rom/commands/graph/class_interface.rb +2 -0
  34. data/lib/rom/commands/graph/input_evaluator.rb +2 -0
  35. data/lib/rom/commands/lazy.rb +2 -0
  36. data/lib/rom/commands/lazy/create.rb +2 -0
  37. data/lib/rom/commands/lazy/delete.rb +2 -0
  38. data/lib/rom/commands/lazy/update.rb +2 -0
  39. data/lib/rom/commands/update.rb +2 -0
  40. data/lib/rom/configuration.rb +2 -0
  41. data/lib/rom/configuration_dsl.rb +2 -0
  42. data/lib/rom/configuration_dsl/command.rb +2 -0
  43. data/lib/rom/configuration_dsl/command_dsl.rb +2 -0
  44. data/lib/rom/configuration_dsl/relation.rb +2 -0
  45. data/lib/rom/configuration_plugin.rb +2 -0
  46. data/lib/rom/constants.rb +3 -0
  47. data/lib/rom/container.rb +2 -0
  48. data/lib/rom/core.rb +4 -1
  49. data/lib/rom/create_container.rb +2 -0
  50. data/lib/rom/data_proxy.rb +2 -0
  51. data/lib/rom/enumerable_dataset.rb +2 -0
  52. data/lib/rom/environment.rb +2 -0
  53. data/lib/rom/gateway.rb +2 -0
  54. data/lib/rom/global.rb +2 -0
  55. data/lib/rom/global/plugin_dsl.rb +2 -0
  56. data/lib/rom/header.rb +198 -0
  57. data/lib/rom/header/attribute.rb +192 -0
  58. data/lib/rom/initializer.rb +2 -0
  59. data/lib/rom/lint/enumerable_dataset.rb +2 -0
  60. data/lib/rom/lint/gateway.rb +2 -0
  61. data/lib/rom/lint/linter.rb +2 -0
  62. data/lib/rom/lint/spec.rb +2 -0
  63. data/lib/rom/lint/test.rb +2 -0
  64. data/lib/rom/mapper.rb +100 -0
  65. data/lib/rom/mapper/attribute_dsl.rb +480 -0
  66. data/lib/rom/mapper/builder.rb +39 -0
  67. data/lib/rom/mapper/configuration_plugin.rb +28 -0
  68. data/lib/rom/mapper/dsl.rb +123 -0
  69. data/lib/rom/mapper/mapper_dsl.rb +45 -0
  70. data/lib/rom/mapper/model_dsl.rb +60 -0
  71. data/lib/rom/mapper_compiler.rb +84 -0
  72. data/lib/rom/mapper_registry.rb +2 -0
  73. data/lib/rom/memory.rb +2 -0
  74. data/lib/rom/memory/associations.rb +2 -0
  75. data/lib/rom/memory/associations/many_to_many.rb +2 -0
  76. data/lib/rom/memory/associations/many_to_one.rb +2 -0
  77. data/lib/rom/memory/associations/one_to_many.rb +2 -0
  78. data/lib/rom/memory/associations/one_to_one.rb +2 -0
  79. data/lib/rom/memory/commands.rb +2 -0
  80. data/lib/rom/memory/dataset.rb +2 -0
  81. data/lib/rom/memory/gateway.rb +2 -0
  82. data/lib/rom/memory/mapper_compiler.rb +2 -0
  83. data/lib/rom/memory/relation.rb +2 -0
  84. data/lib/rom/memory/schema.rb +2 -0
  85. data/lib/rom/memory/storage.rb +2 -0
  86. data/lib/rom/memory/types.rb +2 -0
  87. data/lib/rom/model_builder.rb +103 -0
  88. data/lib/rom/open_struct.rb +37 -0
  89. data/lib/rom/pipeline.rb +2 -0
  90. data/lib/rom/plugin.rb +2 -0
  91. data/lib/rom/plugin_base.rb +2 -0
  92. data/lib/rom/plugin_registry.rb +2 -0
  93. data/lib/rom/plugins/command/schema.rb +2 -0
  94. data/lib/rom/plugins/command/timestamps.rb +2 -0
  95. data/lib/rom/plugins/relation/instrumentation.rb +2 -0
  96. data/lib/rom/plugins/relation/registry_reader.rb +2 -0
  97. data/lib/rom/plugins/schema/timestamps.rb +8 -1
  98. data/lib/rom/processor.rb +30 -0
  99. data/lib/rom/processor/transproc.rb +417 -0
  100. data/lib/rom/registry.rb +2 -0
  101. data/lib/rom/relation.rb +4 -2
  102. data/lib/rom/relation/class_interface.rb +2 -0
  103. data/lib/rom/relation/combined.rb +2 -0
  104. data/lib/rom/relation/commands.rb +2 -0
  105. data/lib/rom/relation/composite.rb +2 -0
  106. data/lib/rom/relation/curried.rb +3 -1
  107. data/lib/rom/relation/graph.rb +2 -0
  108. data/lib/rom/relation/loaded.rb +2 -0
  109. data/lib/rom/relation/materializable.rb +2 -0
  110. data/lib/rom/relation/name.rb +2 -0
  111. data/lib/rom/relation/view_dsl.rb +2 -0
  112. data/lib/rom/relation/wrap.rb +2 -0
  113. data/lib/rom/relation_registry.rb +2 -0
  114. data/lib/rom/schema.rb +39 -6
  115. data/lib/rom/schema/associations_dsl.rb +5 -3
  116. data/lib/rom/schema/dsl.rb +41 -11
  117. data/lib/rom/schema/inferrer.rb +21 -3
  118. data/lib/rom/schema_plugin.rb +2 -0
  119. data/lib/rom/setup.rb +2 -0
  120. data/lib/rom/setup/auto_registration.rb +2 -0
  121. data/lib/rom/setup/auto_registration_strategies/base.rb +3 -1
  122. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +2 -0
  123. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +2 -0
  124. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +2 -0
  125. data/lib/rom/setup/finalize.rb +2 -0
  126. data/lib/rom/setup/finalize/finalize_commands.rb +2 -0
  127. data/lib/rom/setup/finalize/finalize_mappers.rb +2 -0
  128. data/lib/rom/setup/finalize/finalize_relations.rb +2 -0
  129. data/lib/rom/struct.rb +108 -0
  130. data/lib/rom/struct_compiler.rb +110 -0
  131. data/lib/rom/support/configurable.rb +2 -0
  132. data/lib/rom/support/inflector.rb +2 -0
  133. data/lib/rom/support/memoizable.rb +2 -0
  134. data/lib/rom/support/notifications.rb +2 -0
  135. data/lib/rom/transaction.rb +2 -0
  136. data/lib/rom/transformer.rb +34 -0
  137. data/lib/rom/types.rb +10 -3
  138. data/lib/rom/version.rb +3 -1
  139. metadata +37 -21
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/inflector'
2
4
 
3
5
  require 'rom/initializer'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/inflector'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
 
3
5
  require 'rom/constants'
@@ -41,15 +43,19 @@ module ROM
41
43
  # If mapper is set command will be turned into a composite command with
42
44
  # auto-mapping
43
45
  #
44
- # @example
45
- # create_user = rom.commands[:users][:create]
46
- # create_user[name: 'Jane']
46
+ # @overload [](name)
47
+ # @param [Symbol] name The command identifier from the registry
48
+ # @example
49
+ # create_user = rom.commands[:users][:create]
50
+ # create_user[name: 'Jane']
47
51
  #
48
- # # with mapping, assuming :entity mapper is registered for :users relation
49
- # create_user = rom.commands[:users].map_with(:entity)[:create]
50
- # create_user[name: 'Jane'] # => result is send through :entity mapper
52
+ # # with mapping, assuming :entity mapper is registered for :users relation
53
+ # create_user = rom.commands[:users].map_with(:entity)[:create]
54
+ # create_user[name: 'Jane'] # => result is sent through :entity mapper
51
55
  #
52
- # @param [Symbol] name The name of a registered command
56
+ # @overload [](*args)
57
+ # @param [Array] *args {CommandCompiler} arguments
58
+ # @see CommandCompiler#call
53
59
  #
54
60
  # @return [Command,Command::Composite]
55
61
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/commands/create'
2
4
  require 'rom/commands/update'
3
5
  require 'rom/commands/delete'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/class_builder'
2
4
  require 'rom/support/inflector'
3
5
 
@@ -105,8 +107,8 @@ module ROM
105
107
  # end
106
108
  #
107
109
  # @param [Symbol] plugin
108
- # @param [Hash] _options
109
- # @option _options [Symbol] :adapter (:default) first adapter to check for plugin
110
+ # @param [Hash] options
111
+ # @option options [Symbol] :adapter (:default) first adapter to check for plugin
110
112
  #
111
113
  # @api public
112
114
  def use(plugin, options = EMPTY_HASH)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/pipeline'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/command'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/command'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/initializer'
2
4
  require 'rom/pipeline'
3
5
  require 'rom/commands/graph/class_interface'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/commands/graph/input_evaluator'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Commands
3
5
  class Graph
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/commands/composite'
2
4
  require 'rom/commands/graph'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Commands
3
5
  class Lazy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Commands
3
5
  class Lazy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Commands
3
5
  class Lazy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/command'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
 
3
5
  require 'rom/environment'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/configuration_dsl/relation'
2
4
  require 'rom/configuration_dsl/command_dsl'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/inflector'
2
4
  require 'dry/core/class_builder'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/configuration_dsl/command'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/class_builder'
2
4
  require 'rom/support/inflector'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/plugin_base'
2
4
 
3
5
  module ROM
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/constants'
2
4
 
3
5
  # Constants and errors common in the whole library
@@ -20,6 +22,7 @@ module ROM
20
22
  EnvAlreadyFinalizedError = Class.new(StandardError)
21
23
  RelationAlreadyDefinedError = Class.new(StandardError)
22
24
  MapperAlreadyDefinedError = Class.new(StandardError)
25
+ MapperMisconfiguredError = Class.new(StandardError)
23
26
  NoRelationError = Class.new(StandardError)
24
27
  InvalidRelationName = Class.new(StandardError)
25
28
  CommandError = Class.new(StandardError)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/container'
2
4
 
3
5
  require 'rom/cache'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
  require 'dry/core/constants'
3
5
 
@@ -9,7 +11,8 @@ require 'rom/configuration_plugin'
9
11
  require 'rom/plugin'
10
12
  require 'rom/schema_plugin'
11
13
  require 'rom/relation'
12
- require 'rom-mapper'
14
+ require 'rom/mapper'
15
+ require 'rom/processor/transproc'
13
16
  require 'rom/mapper/configuration_plugin'
14
17
  require 'rom/commands'
15
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/configuration'
2
4
  require 'rom/environment'
3
5
  require 'rom/setup'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  # Helper module for dataset classes
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/initializer'
2
4
  require 'rom/data_proxy'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/support/configurable'
2
4
  require 'rom/gateway'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/class_attributes'
2
4
 
3
5
  require 'rom/transaction'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rom/plugin_registry'
2
4
  require 'rom/global/plugin_dsl'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ROM
2
4
  module Global
3
5
  # plugin registration DSL
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rom/header/attribute'
4
+
5
+ module ROM
6
+ # Header provides information about data mapping of a specific relation
7
+ #
8
+ # Processors use headers to build objects that process raw relations that go
9
+ # through mappers.
10
+ #
11
+ # @private
12
+ class Header
13
+ include Enumerable
14
+ include Dry::Equalizer(:attributes, :model)
15
+
16
+ # @return [Class] optional model associated with a header
17
+ #
18
+ # @api private
19
+ attr_reader :model
20
+
21
+ # @api private
22
+ attr_reader :reject_keys
23
+
24
+ # @api private
25
+ attr_reader :copy_keys
26
+
27
+ # @api private
28
+ attr_reader :attributes
29
+
30
+ # @return [Hash] attribute key/name mapping for all primitive attributes
31
+ #
32
+ # @api private
33
+ attr_reader :mapping
34
+
35
+ # @return [Array] all attribute keys that are in a tuple
36
+ #
37
+ # @api private
38
+ attr_reader :tuple_keys
39
+
40
+ # @return [Array] all attribute names that are popping from a tuple
41
+ #
42
+ # @api private
43
+ attr_reader :pop_keys
44
+
45
+ # Coerce array with attribute definitions into a header object
46
+ #
47
+ # @param [Array<Array>] input attribute name/option pairs
48
+ # @param [Hash] options
49
+ #
50
+ # @return [Header]
51
+ #
52
+ # @api private
53
+ def self.coerce(input, options = {})
54
+ if input.instance_of?(self)
55
+ input
56
+ else
57
+ attributes = input.each_with_object({}) { |pair, h|
58
+ h[pair.first] = Attribute.coerce(pair)
59
+ }
60
+
61
+ new(attributes, options)
62
+ end
63
+ end
64
+
65
+ # @api private
66
+ def initialize(attributes, options = {})
67
+ @options = options
68
+ @model = options[:model]
69
+ @copy_keys = options.fetch(:copy_keys, false)
70
+ @reject_keys = options.fetch(:reject_keys, false)
71
+
72
+ @attributes = attributes
73
+ initialize_mapping
74
+ initialize_tuple_keys
75
+ initialize_pop_keys
76
+ end
77
+
78
+ # Iterate over attributes
79
+ #
80
+ # @yield [Attribute]
81
+ #
82
+ # @api private
83
+ def each
84
+ attributes.each_value { |attribute| yield(attribute) }
85
+ end
86
+
87
+ # Return if there are any aliased attributes
88
+ #
89
+ # @api private
90
+ def aliased?
91
+ any?(&:aliased?)
92
+ end
93
+
94
+ # Return attribute keys
95
+ #
96
+ # An attribute key corresponds to tuple attribute names
97
+ #
98
+ # @api private
99
+ def keys
100
+ attributes.keys
101
+ end
102
+
103
+ # Return attribute identified by its name
104
+ #
105
+ # @return [Attribute]
106
+ #
107
+ # @api private
108
+ def [](name)
109
+ attributes.fetch(name)
110
+ end
111
+
112
+ # Return all Combined attributes
113
+ #
114
+ # @return [Array<Combined>]
115
+ #
116
+ # @api private
117
+ def combined
118
+ by_type(Combined)
119
+ end
120
+
121
+ # Returns all attributes that require preprocessing
122
+ #
123
+ # @return [Array<Group,Fold>]
124
+ #
125
+ # @api private
126
+ def preprocessed
127
+ by_type(Group, Fold)
128
+ end
129
+
130
+ # Returns all attributes that require postprocessing
131
+ #
132
+ # @return [Array<Ungroup,Unfold>]
133
+ #
134
+ # @api private
135
+ def postprocessed
136
+ by_type(Ungroup, Unfold)
137
+ end
138
+
139
+ # Return all Wrap attributes
140
+ #
141
+ # @return [Array<Wrap>]
142
+ #
143
+ # @api private
144
+ def wraps
145
+ by_type(Wrap)
146
+ end
147
+
148
+ # Return all non-primitive attributes that don't require mapping
149
+ #
150
+ # @return [Array<Group,Fold,Ungroup,Unfold,Wrap,Unwrap>]
151
+ #
152
+ # @api private
153
+ def non_primitives
154
+ preprocessed + wraps
155
+ end
156
+
157
+ # Return all primitive attributes that require mapping
158
+ #
159
+ # @return [Array<Attribute>]
160
+ #
161
+ # @api private
162
+ def primitives
163
+ to_a - non_primitives
164
+ end
165
+
166
+ private
167
+
168
+ # Find all attribute matching specific attribute class (not kind)
169
+ #
170
+ # @return [Array<Attribute>]
171
+ #
172
+ # @api private
173
+ def by_type(*types)
174
+ select { |attribute| types.include?(attribute.class) }
175
+ end
176
+
177
+ # Set mapping hash from primitive attributes
178
+ #
179
+ # @api private
180
+ def initialize_mapping
181
+ @mapping = primitives.map(&:mapping).reduce(:merge) || {}
182
+ end
183
+
184
+ # Set all tuple keys from all attributes going deep into Wrap and Group too
185
+ #
186
+ # @api private
187
+ def initialize_tuple_keys
188
+ @tuple_keys = mapping.keys.flatten + non_primitives.flat_map(&:tuple_keys)
189
+ end
190
+
191
+ # Set all tuple keys from all attributes popping from Unwrap and Ungroup
192
+ #
193
+ # @api private
194
+ def initialize_pop_keys
195
+ @pop_keys = mapping.values + non_primitives.flat_map(&:tuple_keys)
196
+ end
197
+ end
198
+ end