rom 3.3.3 → 4.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -599
  3. data/lib/rom/version.rb +1 -1
  4. data/lib/rom.rb +3 -44
  5. metadata +19 -295
  6. data/.gitignore +0 -24
  7. data/.rspec +0 -3
  8. data/.rubocop.yml +0 -87
  9. data/.rubocop_todo.yml +0 -46
  10. data/.travis.yml +0 -24
  11. data/.yardopts +0 -2
  12. data/CODE_OF_CONDUCT.md +0 -13
  13. data/CONTRIBUTING.md +0 -1
  14. data/Gemfile +0 -54
  15. data/Guardfile +0 -24
  16. data/Rakefile +0 -28
  17. data/lib/rom/array_dataset.rb +0 -44
  18. data/lib/rom/association_set.rb +0 -49
  19. data/lib/rom/auto_curry.rb +0 -55
  20. data/lib/rom/command.rb +0 -494
  21. data/lib/rom/command_registry.rb +0 -148
  22. data/lib/rom/commands/class_interface.rb +0 -270
  23. data/lib/rom/commands/composite.rb +0 -53
  24. data/lib/rom/commands/create.rb +0 -13
  25. data/lib/rom/commands/delete.rb +0 -14
  26. data/lib/rom/commands/graph/builder.rb +0 -176
  27. data/lib/rom/commands/graph/class_interface.rb +0 -62
  28. data/lib/rom/commands/graph/input_evaluator.rb +0 -62
  29. data/lib/rom/commands/graph.rb +0 -95
  30. data/lib/rom/commands/lazy/create.rb +0 -23
  31. data/lib/rom/commands/lazy/delete.rb +0 -27
  32. data/lib/rom/commands/lazy/update.rb +0 -34
  33. data/lib/rom/commands/lazy.rb +0 -99
  34. data/lib/rom/commands/result.rb +0 -96
  35. data/lib/rom/commands/update.rb +0 -14
  36. data/lib/rom/commands.rb +0 -3
  37. data/lib/rom/configuration.rb +0 -90
  38. data/lib/rom/configuration_dsl/command.rb +0 -41
  39. data/lib/rom/configuration_dsl/command_dsl.rb +0 -35
  40. data/lib/rom/configuration_dsl/mapper.rb +0 -36
  41. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -43
  42. data/lib/rom/configuration_dsl/relation.rb +0 -26
  43. data/lib/rom/configuration_dsl.rb +0 -107
  44. data/lib/rom/configuration_plugin.rb +0 -17
  45. data/lib/rom/constants.rb +0 -36
  46. data/lib/rom/container.rb +0 -233
  47. data/lib/rom/create_container.rb +0 -60
  48. data/lib/rom/data_proxy.rb +0 -94
  49. data/lib/rom/enumerable_dataset.rb +0 -68
  50. data/lib/rom/environment.rb +0 -70
  51. data/lib/rom/gateway.rb +0 -196
  52. data/lib/rom/global/plugin_dsl.rb +0 -47
  53. data/lib/rom/global.rb +0 -58
  54. data/lib/rom/initializer.rb +0 -26
  55. data/lib/rom/lint/enumerable_dataset.rb +0 -54
  56. data/lib/rom/lint/gateway.rb +0 -120
  57. data/lib/rom/lint/linter.rb +0 -78
  58. data/lib/rom/lint/spec.rb +0 -20
  59. data/lib/rom/lint/test.rb +0 -98
  60. data/lib/rom/mapper_registry.rb +0 -35
  61. data/lib/rom/memory/commands.rb +0 -56
  62. data/lib/rom/memory/dataset.rb +0 -97
  63. data/lib/rom/memory/gateway.rb +0 -64
  64. data/lib/rom/memory/relation.rb +0 -62
  65. data/lib/rom/memory/schema.rb +0 -13
  66. data/lib/rom/memory/storage.rb +0 -59
  67. data/lib/rom/memory/types.rb +0 -9
  68. data/lib/rom/memory.rb +0 -4
  69. data/lib/rom/pipeline.rb +0 -122
  70. data/lib/rom/plugin.rb +0 -20
  71. data/lib/rom/plugin_base.rb +0 -40
  72. data/lib/rom/plugin_registry.rb +0 -173
  73. data/lib/rom/plugins/command/schema.rb +0 -37
  74. data/lib/rom/plugins/configuration/configuration_dsl.rb +0 -21
  75. data/lib/rom/plugins/relation/instrumentation.rb +0 -51
  76. data/lib/rom/plugins/relation/key_inference.rb +0 -48
  77. data/lib/rom/plugins/relation/registry_reader.rb +0 -33
  78. data/lib/rom/registry.rb +0 -50
  79. data/lib/rom/relation/class_interface.rb +0 -356
  80. data/lib/rom/relation/composite.rb +0 -46
  81. data/lib/rom/relation/curried.rb +0 -109
  82. data/lib/rom/relation/graph.rb +0 -125
  83. data/lib/rom/relation/loaded.rb +0 -127
  84. data/lib/rom/relation/materializable.rb +0 -66
  85. data/lib/rom/relation/name.rb +0 -102
  86. data/lib/rom/relation/view_dsl.rb +0 -64
  87. data/lib/rom/relation.rb +0 -250
  88. data/lib/rom/relation_registry.rb +0 -9
  89. data/lib/rom/schema/attribute.rb +0 -390
  90. data/lib/rom/schema/dsl.rb +0 -67
  91. data/lib/rom/schema.rb +0 -407
  92. data/lib/rom/setup/auto_registration.rb +0 -74
  93. data/lib/rom/setup/auto_registration_strategies/base.rb +0 -16
  94. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +0 -63
  95. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +0 -20
  96. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +0 -18
  97. data/lib/rom/setup/finalize/finalize_commands.rb +0 -47
  98. data/lib/rom/setup/finalize/finalize_mappers.rb +0 -36
  99. data/lib/rom/setup/finalize/finalize_relations.rb +0 -83
  100. data/lib/rom/setup/finalize.rb +0 -152
  101. data/lib/rom/setup.rb +0 -65
  102. data/lib/rom/support/configurable.rb +0 -85
  103. data/lib/rom/transaction.rb +0 -24
  104. data/lib/rom/types.rb +0 -49
  105. data/log/.gitkeep +0 -0
  106. data/rakelib/benchmark.rake +0 -15
  107. data/rakelib/mutant.rake +0 -19
  108. data/rakelib/rubocop.rake +0 -18
  109. data/rom.gemspec +0 -25
  110. data/spec/fixtures/app/commands/create_user.rb +0 -2
  111. data/spec/fixtures/app/mappers/user_list.rb +0 -2
  112. data/spec/fixtures/app/my_commands/create_user.rb +0 -2
  113. data/spec/fixtures/app/my_mappers/user_list.rb +0 -2
  114. data/spec/fixtures/app/my_relations/users.rb +0 -2
  115. data/spec/fixtures/app/relations/users.rb +0 -2
  116. data/spec/fixtures/custom/commands/create_user.rb +0 -6
  117. data/spec/fixtures/custom/mappers/user_list.rb +0 -6
  118. data/spec/fixtures/custom/relations/users.rb +0 -6
  119. data/spec/fixtures/custom_namespace/commands/create_customer.rb +0 -8
  120. data/spec/fixtures/custom_namespace/mappers/customer_list.rb +0 -8
  121. data/spec/fixtures/custom_namespace/relations/customers.rb +0 -8
  122. data/spec/fixtures/lib/persistence/commands/create_user.rb +0 -6
  123. data/spec/fixtures/lib/persistence/mappers/user_list.rb +0 -6
  124. data/spec/fixtures/lib/persistence/my_commands/create_user.rb +0 -6
  125. data/spec/fixtures/lib/persistence/my_mappers/user_list.rb +0 -6
  126. data/spec/fixtures/lib/persistence/my_relations/users.rb +0 -6
  127. data/spec/fixtures/lib/persistence/relations/users.rb +0 -6
  128. data/spec/fixtures/wrong/commands/create_customer.rb +0 -8
  129. data/spec/fixtures/wrong/mappers/customer_list.rb +0 -8
  130. data/spec/fixtures/wrong/relations/customers.rb +0 -8
  131. data/spec/integration/command_registry_spec.rb +0 -47
  132. data/spec/integration/commands/create_spec.rb +0 -157
  133. data/spec/integration/commands/delete_spec.rb +0 -67
  134. data/spec/integration/commands/error_handling_spec.rb +0 -25
  135. data/spec/integration/commands/graph_builder_spec.rb +0 -213
  136. data/spec/integration/commands/graph_spec.rb +0 -294
  137. data/spec/integration/commands/update_spec.rb +0 -86
  138. data/spec/integration/commands_spec.rb +0 -67
  139. data/spec/integration/gateways/extending_relations_spec.rb +0 -58
  140. data/spec/integration/gateways/setting_logger_spec.rb +0 -34
  141. data/spec/integration/mappers/combine_spec.rb +0 -117
  142. data/spec/integration/mappers/deep_embedded_spec.rb +0 -44
  143. data/spec/integration/mappers/definition_dsl_spec.rb +0 -206
  144. data/spec/integration/mappers/embedded_spec.rb +0 -62
  145. data/spec/integration/mappers/exclude_spec.rb +0 -27
  146. data/spec/integration/mappers/fold_spec.rb +0 -71
  147. data/spec/integration/mappers/group_spec.rb +0 -163
  148. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +0 -51
  149. data/spec/integration/mappers/prefix_separator_spec.rb +0 -52
  150. data/spec/integration/mappers/prefix_spec.rb +0 -48
  151. data/spec/integration/mappers/prefixing_attributes_spec.rb +0 -37
  152. data/spec/integration/mappers/registering_custom_mappers_spec.rb +0 -28
  153. data/spec/integration/mappers/renaming_attributes_spec.rb +0 -125
  154. data/spec/integration/mappers/reusing_mappers_spec.rb +0 -43
  155. data/spec/integration/mappers/step_spec.rb +0 -119
  156. data/spec/integration/mappers/symbolizing_attributes_spec.rb +0 -77
  157. data/spec/integration/mappers/unfold_spec.rb +0 -92
  158. data/spec/integration/mappers/ungroup_spec.rb +0 -126
  159. data/spec/integration/mappers/unwrap_spec.rb +0 -93
  160. data/spec/integration/mappers/wrap_spec.rb +0 -155
  161. data/spec/integration/memory/commands/create_spec.rb +0 -23
  162. data/spec/integration/memory/commands/delete_spec.rb +0 -23
  163. data/spec/integration/memory/commands/update_spec.rb +0 -23
  164. data/spec/integration/multi_env_spec.rb +0 -69
  165. data/spec/integration/multi_repo_spec.rb +0 -46
  166. data/spec/integration/relations/default_dataset_spec.rb +0 -38
  167. data/spec/integration/relations/inheritance_spec.rb +0 -37
  168. data/spec/integration/relations/reading_spec.rb +0 -169
  169. data/spec/integration/relations/registry_dsl_spec.rb +0 -45
  170. data/spec/integration/setup_spec.rb +0 -193
  171. data/spec/shared/command_behavior.rb +0 -28
  172. data/spec/shared/command_graph.rb +0 -54
  173. data/spec/shared/container.rb +0 -9
  174. data/spec/shared/enumerable_dataset.rb +0 -52
  175. data/spec/shared/gateway_only.rb +0 -6
  176. data/spec/shared/materializable.rb +0 -36
  177. data/spec/shared/no_container.rb +0 -16
  178. data/spec/shared/one_behavior.rb +0 -26
  179. data/spec/shared/proxy.rb +0 -0
  180. data/spec/shared/users_and_tasks.rb +0 -10
  181. data/spec/spec_helper.rb +0 -59
  182. data/spec/support/constant_leak_finder.rb +0 -14
  183. data/spec/support/mutant.rb +0 -10
  184. data/spec/support/schema.rb +0 -14
  185. data/spec/support/types.rb +0 -5
  186. data/spec/test/memory_repository_lint_test.rb +0 -27
  187. data/spec/unit/rom/array_dataset_spec.rb +0 -59
  188. data/spec/unit/rom/association_set_spec.rb +0 -48
  189. data/spec/unit/rom/auto_curry_spec.rb +0 -71
  190. data/spec/unit/rom/commands/graph_spec.rb +0 -192
  191. data/spec/unit/rom/commands/lazy_spec.rb +0 -310
  192. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +0 -343
  193. data/spec/unit/rom/commands/result_spec.rb +0 -70
  194. data/spec/unit/rom/commands_spec.rb +0 -188
  195. data/spec/unit/rom/configurable_spec.rb +0 -49
  196. data/spec/unit/rom/configuration_spec.rb +0 -61
  197. data/spec/unit/rom/container_spec.rb +0 -109
  198. data/spec/unit/rom/create_container_spec.rb +0 -151
  199. data/spec/unit/rom/enumerable_dataset_spec.rb +0 -15
  200. data/spec/unit/rom/environment_spec.rb +0 -123
  201. data/spec/unit/rom/gateway_spec.rb +0 -146
  202. data/spec/unit/rom/mapper_registry_spec.rb +0 -25
  203. data/spec/unit/rom/memory/commands_spec.rb +0 -43
  204. data/spec/unit/rom/memory/dataset_spec.rb +0 -31
  205. data/spec/unit/rom/memory/gateway_spec.rb +0 -12
  206. data/spec/unit/rom/memory/inheritance_spec.rb +0 -32
  207. data/spec/unit/rom/memory/relation_spec.rb +0 -121
  208. data/spec/unit/rom/memory/storage_spec.rb +0 -45
  209. data/spec/unit/rom/plugin_spec.rb +0 -150
  210. data/spec/unit/rom/plugins/command/schema_spec.rb +0 -66
  211. data/spec/unit/rom/plugins/relation/instrumentation_spec.rb +0 -44
  212. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +0 -85
  213. data/spec/unit/rom/registry_spec.rb +0 -86
  214. data/spec/unit/rom/relation/attribute_reader_spec.rb +0 -17
  215. data/spec/unit/rom/relation/call_spec.rb +0 -51
  216. data/spec/unit/rom/relation/composite_spec.rb +0 -106
  217. data/spec/unit/rom/relation/curried_spec.rb +0 -67
  218. data/spec/unit/rom/relation/graph_spec.rb +0 -106
  219. data/spec/unit/rom/relation/lazy/combine_spec.rb +0 -165
  220. data/spec/unit/rom/relation/lazy/graph_spec.rb +0 -165
  221. data/spec/unit/rom/relation/lazy_spec.rb +0 -214
  222. data/spec/unit/rom/relation/loaded_spec.rb +0 -53
  223. data/spec/unit/rom/relation/name_spec.rb +0 -58
  224. data/spec/unit/rom/relation/output_schema_spec.rb +0 -28
  225. data/spec/unit/rom/relation/schema_spec.rb +0 -259
  226. data/spec/unit/rom/relation/view_spec.rb +0 -158
  227. data/spec/unit/rom/relation_spec.rb +0 -252
  228. data/spec/unit/rom/schema/accessing_attributes_spec.rb +0 -52
  229. data/spec/unit/rom/schema/append_spec.rb +0 -17
  230. data/spec/unit/rom/schema/exclude_spec.rb +0 -15
  231. data/spec/unit/rom/schema/finalize_spec.rb +0 -59
  232. data/spec/unit/rom/schema/key_predicate_spec.rb +0 -15
  233. data/spec/unit/rom/schema/merge_spec.rb +0 -17
  234. data/spec/unit/rom/schema/prefix_spec.rb +0 -16
  235. data/spec/unit/rom/schema/project_spec.rb +0 -15
  236. data/spec/unit/rom/schema/rename_spec.rb +0 -22
  237. data/spec/unit/rom/schema/type_spec.rb +0 -49
  238. data/spec/unit/rom/schema/uniq_spec.rb +0 -21
  239. data/spec/unit/rom/schema/wrap_spec.rb +0 -18
  240. data/spec/unit/rom/schema_spec.rb +0 -10
  241. data/spec/unit/rom/setup/auto_registration_spec.rb +0 -214
@@ -1,68 +0,0 @@
1
- require 'rom/initializer'
2
- require 'rom/data_proxy'
3
-
4
- module ROM
5
- # A helper module that adds data-proxy behavior to an enumerable object
6
- #
7
- # This module is intended to be used by gateways
8
- #
9
- # Class that includes this module can define `row_proc` class method which
10
- # must return a proc-like object which will be used to process each element
11
- # in the enumerable
12
- #
13
- # @example
14
- # class MyDataset
15
- # include ROM::EnumerableDataset
16
- #
17
- # def self.row_proc
18
- # -> tuple { tuple.each_with_object({}) { |(k,v), h| h[k.to_sym] = v } }
19
- # end
20
- # end
21
- #
22
- # ds = MyDataset.new([{ 'name' => 'Jane' }, [:name])
23
- # ds.to_a # => { :name => 'Jane' }
24
- #
25
- # @api public
26
- module EnumerableDataset
27
- extend DataProxy::ClassMethods
28
- include Enumerable
29
-
30
- # Coerce a dataset to an array
31
- #
32
- # @return [Array]
33
- #
34
- # @api public
35
- alias_method :to_ary, :to_a
36
-
37
- # Included hook which extends a class with DataProxy behavior
38
- #
39
- # This module can also be included into other modules so we apply the
40
- # extension only for classes
41
- #
42
- # @api private
43
- def self.included(klass)
44
- return unless klass.is_a?(Class)
45
-
46
- klass.class_eval do
47
- extend Initializer
48
- include DataProxy
49
-
50
- param :data
51
- end
52
- end
53
-
54
- forward :take
55
-
56
- [
57
- :chunk, :collect, :collect_concat, :drop_while, :find_all, :flat_map,
58
- :grep, :map, :reject, :select, :sort, :sort_by, :take_while
59
- ].each do |method|
60
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
61
- def #{method}(*args, &block)
62
- return to_enum unless block
63
- self.class.new(super(*args, &block), options)
64
- end
65
- RUBY
66
- end
67
- end
68
- end
@@ -1,70 +0,0 @@
1
- require 'rom/support/configurable'
2
- require 'rom/gateway'
3
-
4
- module ROM
5
- # Core gateway configuration interface
6
- #
7
- # @api public
8
- class Environment
9
- include Configurable
10
-
11
- attr_reader :gateways, :gateways_map
12
-
13
- # @api public
14
- def initialize(*args)
15
- @gateways = {}
16
- @gateways_map = {}
17
-
18
- configure_gateways(*args) unless args.empty?
19
- end
20
-
21
- private
22
-
23
- def configure_gateways(*args)
24
- normalized_gateway_args = normalize_gateway_args(*args)
25
- normalized_gateways = normalize_gateways(normalized_gateway_args)
26
-
27
- @gateways, @gateways_map = normalized_gateways.values_at(:gateways, :map)
28
-
29
- normalized_gateway_args.each_with_object(config) do |(name, gateway_config), config|
30
- options = gateway_config.is_a?(Array) && gateway_config.last
31
- load_config(config.gateways[name], options) if options.is_a?(Hash)
32
- end
33
- end
34
-
35
-
36
- # @api private
37
- def normalize_gateway_args(*args)
38
- args.first.is_a?(Hash) ? args.first : {default: args}
39
- end
40
-
41
- # Build gateways using the setup interface
42
- #
43
- # @api private
44
- def normalize_gateways(gateways_config)
45
- gateways_config.each_with_object({map: {}, gateways: {}}) do |(name, spec), hash|
46
- identifier, *args = Array(spec)
47
-
48
- if identifier.is_a?(Gateway)
49
- gateway = identifier
50
- else
51
- gateway = Gateway.setup(identifier, *(args.flatten))
52
- hash[:map][gateway] = identifier
53
- end
54
-
55
- hash[:gateways][name] = gateway
56
- end
57
- end
58
-
59
- # @api private
60
- def load_config(config, hash)
61
- hash.each do |key, value|
62
- if value.is_a?(Hash)
63
- load_config(config[key], value)
64
- else
65
- config.send("#{key}=", value)
66
- end
67
- end
68
- end
69
- end
70
- end
data/lib/rom/gateway.rb DELETED
@@ -1,196 +0,0 @@
1
- require 'dry/core/class_attributes'
2
-
3
- require 'rom/transaction'
4
-
5
- module ROM
6
- # Abstract gateway class
7
- #
8
- # Every adapter needs to inherit from this class and implement
9
- # required interface
10
- #
11
- # @abstract
12
- #
13
- # @api public
14
- class Gateway
15
- extend Dry::Core::ClassAttributes
16
-
17
- defines :adapter
18
-
19
- # @!attribute [r] connection
20
- # @return [Object] The gateway's connection object (type varies across adapters)
21
- attr_reader :connection
22
-
23
- # Set up a gateway
24
- #
25
- # @overload setup(type, *args)
26
- # Sets up a single-gateway given a gateway type.
27
- # For custom gateways, create an instance and pass it directly.
28
- #
29
- # @example
30
- # module SuperDB
31
- # class Gateway < ROM::Gateway
32
- # def initialize(options)
33
- # end
34
- # end
35
- # end
36
- #
37
- # ROM.register_adapter(:super_db, SuperDB)
38
- #
39
- # Gateway.setup(:super_db, some: 'options')
40
- # # SuperDB::Gateway.new(some: 'options') is called
41
- #
42
- # @param [Symbol] type Registered gateway identifier
43
- # @param [Array] args Additional gateway options
44
- #
45
- # @overload setup(gateway)
46
- # Set up a gateway instance
47
- #
48
- # @example
49
- # module SuperDB
50
- # class Gateway < ROM::Gateway
51
- # def initialize(options)
52
- # end
53
- # end
54
- # end
55
- #
56
- # ROM.register_adapter(:super_db, SuperDB)
57
- #
58
- # Gateway.setup(SuperDB::Gateway.new(some: 'options'))
59
- #
60
- # @param [Gateway] gateway
61
- #
62
- # @return [Gateway] a specific gateway subclass
63
- #
64
- # @api public
65
- def self.setup(gateway_or_scheme, *args)
66
- case gateway_or_scheme
67
- when String
68
- raise ArgumentError, <<-STRING.gsub(/^ {10}/, '')
69
- URIs without an explicit scheme are not supported anymore.
70
- See https://github.com/rom-rb/rom/blob/master/CHANGELOG.md
71
- STRING
72
- when Symbol
73
- klass = class_from_symbol(gateway_or_scheme)
74
-
75
- if klass.instance_method(:initialize).arity == 0
76
- klass.new
77
- else
78
- klass.new(*args)
79
- end
80
- else
81
- if args.empty?
82
- gateway_or_scheme
83
- else
84
- raise ArgumentError, "Can't accept arguments when passing an instance"
85
- end
86
- end
87
- end
88
-
89
- # Get gateway subclass for a specific adapter
90
- #
91
- # @param [Symbol] type Adapter identifier
92
- #
93
- # @return [Class]
94
- #
95
- # @api private
96
- def self.class_from_symbol(type)
97
- adapter = ROM.adapters.fetch(type) {
98
- begin
99
- require "rom/#{type}"
100
- rescue LoadError
101
- raise AdapterLoadError, "Failed to load adapter rom/#{type}"
102
- end
103
-
104
- ROM.adapters.fetch(type)
105
- }
106
-
107
- adapter.const_get(:Gateway)
108
- end
109
-
110
- # Returns the adapter, defined for the class
111
- #
112
- # @return [Symbol]
113
- #
114
- # @api public
115
- def adapter
116
- self.class.adapter || raise(
117
- MissingAdapterIdentifierError,
118
- "gateway class +#{self}+ is missing the adapter identifier"
119
- )
120
- end
121
-
122
- # A generic interface for setting up a logger
123
- #
124
- # This is not a required interface, it's a no-op by default
125
- #
126
- # @abstract
127
- #
128
- # @api public
129
- def use_logger(*)
130
- # noop
131
- end
132
-
133
- # A generic interface for returning default logger
134
- #
135
- # Adapters should implement this method as handling loggers is different
136
- # across adapters. This is a no-op by default and returns nil.
137
- #
138
- # @return [NilClass]
139
- #
140
- # @api public
141
- def logger
142
- # noop
143
- end
144
-
145
- # Extension hook for adding gateway-specific behavior to a command class
146
- #
147
- # This simply returns back the class by default
148
- #
149
- # @param [Class] klass The command class
150
- # @param [Object] _dataset The dataset that will be used with this command class
151
- #
152
- # @return [Class]
153
- #
154
- # @api public
155
- def extend_command_class(klass, _dataset)
156
- klass
157
- end
158
-
159
- # Schema inference hook
160
- #
161
- # Every gateway that supports schema inference should implement this method
162
- #
163
- # @return [Array] An array with dataset names
164
- #
165
- # @api private
166
- def schema
167
- []
168
- end
169
-
170
- # Disconnect is optional and it's a no-op by default
171
- #
172
- # @api public
173
- def disconnect
174
- # noop
175
- end
176
-
177
- # Runs a block inside a transaction. The underlying transaction engine
178
- # is adapter-specific
179
- #
180
- # @param [Hash] Transaction options
181
- # @return The result of yielding the block or +nil+ if
182
- # the transaction was rolled back
183
- #
184
- # @api public
185
- def transaction(opts = EMPTY_HASH, &block)
186
- transaction_runner(opts).run(opts, &block)
187
- end
188
-
189
- private
190
-
191
- # @api private
192
- def transaction_runner(_)
193
- Transaction::NoOp
194
- end
195
- end
196
- end
@@ -1,47 +0,0 @@
1
- module ROM
2
- module Global
3
- # plugin registration DSL
4
- #
5
- # @private
6
- class PluginDSL
7
- # Default options passed to plugin registration
8
- #
9
- # @return [Hash]
10
- #
11
- # @api private
12
- attr_reader :defaults
13
-
14
- # Plugin registry
15
- #
16
- # @return [PluginRegistry]
17
- #
18
- # @api private
19
- attr_reader :registry
20
-
21
- # @api private
22
- def initialize(registry, defaults = EMPTY_HASH, &block)
23
- @registry = registry
24
- @defaults = defaults
25
- instance_exec(&block)
26
- end
27
-
28
- # Register a plugin
29
- #
30
- # @param [Symbol] name of the plugin
31
- # @param [Module] mod to include
32
- # @param [Hash] options
33
- #
34
- # @api public
35
- def register(name, mod, options = EMPTY_HASH)
36
- registry.register(name, mod, defaults.merge(options))
37
- end
38
-
39
- # Register plugins for a specific adapter
40
- #
41
- # @param [Symbol] adapter type
42
- def adapter(type, &block)
43
- self.class.new(registry, adapter: type, &block)
44
- end
45
- end
46
- end
47
- end
data/lib/rom/global.rb DELETED
@@ -1,58 +0,0 @@
1
- require 'rom/plugin_registry'
2
- require 'rom/global/plugin_dsl'
3
-
4
- module ROM
5
- # Globally accessible public interface exposed via ROM module
6
- #
7
- # @api public
8
- module Global
9
- # Set base global registries in ROM constant
10
- #
11
- # @api private
12
- def self.extended(rom)
13
- super
14
-
15
- rom.instance_variable_set('@adapters', {})
16
- rom.instance_variable_set('@plugin_registry', PluginRegistry.new)
17
- end
18
-
19
- # An internal adapter identifier => adapter module map used by setup
20
- #
21
- # @return [Hash<Symbol=>Module>]
22
- #
23
- # @api private
24
- attr_reader :adapters
25
-
26
- # An internal identifier => plugin map used by the setup
27
- #
28
- # @return [Hash]
29
- #
30
- # @api private
31
- attr_reader :plugin_registry
32
-
33
- # Global plugin setup DSL
34
- #
35
- # @example
36
- # ROM.plugins do
37
- # register :publisher, Plugin::Publisher, type: :command
38
- # end
39
- #
40
- # @example
41
- def plugins(*args, &block)
42
- PluginDSL.new(plugin_registry, *args, &block)
43
- end
44
-
45
- # Register adapter namespace under a specified identifier
46
- #
47
- # @param [Symbol] identifier
48
- # @param [Class,Module] adapter
49
- #
50
- # @return [self]
51
- #
52
- # @api private
53
- def register_adapter(identifier, adapter)
54
- adapters[identifier] = adapter
55
- self
56
- end
57
- end
58
- end
@@ -1,26 +0,0 @@
1
- require 'dry-initializer'
2
-
3
- module ROM
4
-
5
- # @api private
6
- module Initializer
7
-
8
- # @api private
9
- def self.extended(base)
10
- base.extend(Dry::Initializer[undefined: false])
11
- base.include(InstanceMethods)
12
- end
13
-
14
- # @api private
15
- module InstanceMethods
16
- # Instance options
17
- #
18
- # @return [Hash]
19
- #
20
- # @api public
21
- def options
22
- @__options__
23
- end
24
- end
25
- end
26
- end
@@ -1,54 +0,0 @@
1
- require 'rom/lint/linter'
2
-
3
- module ROM
4
- module Lint
5
- # Ensures that a [ROM::EnumerableDataset] extension correctly yields
6
- # arrays and tuples
7
- #
8
- # @api public
9
- class EnumerableDataset < ROM::Lint::Linter
10
- # The linted subject
11
- #
12
- # @api public
13
- attr_reader :dataset
14
-
15
- # The expected data
16
- #
17
- # @api public
18
- attr_reader :data
19
-
20
- # Create a linter for EnumerableDataset
21
- #
22
- # @param [EnumerableDataset] dataset the linted subject
23
- # @param [Object] data the expected data
24
- #
25
- # @api public
26
- def initialize(dataset, data)
27
- @dataset = dataset
28
- @data = data
29
- end
30
-
31
- # Lint: Ensure that +dataset+ yield tuples via +each+
32
- #
33
- # @api public
34
- def lint_each
35
- result = []
36
- dataset.each do |tuple|
37
- result << tuple
38
- end
39
- return if result == data
40
-
41
- complain "#{dataset.class}#each must yield tuples"
42
- end
43
-
44
- # Lint: Ensure that +dataset+'s array equals to expected +data+
45
- #
46
- # @api public
47
- def lint_to_a
48
- return if dataset.to_a == data
49
-
50
- complain "#{dataset.class}#to_a must cast dataset to an array"
51
- end
52
- end
53
- end
54
- end
@@ -1,120 +0,0 @@
1
- require 'rom/lint/linter'
2
-
3
- module ROM
4
- module Lint
5
- # Ensures that a [ROM::Gateway] extension provides datasets through the
6
- # expected methods
7
- #
8
- # @api public
9
- class Gateway < ROM::Lint::Linter
10
- # The gateway identifier e.g. +:memory+
11
- #
12
- # @api public
13
- attr_reader :identifier
14
-
15
- # The gateway class
16
- #
17
- # @api public
18
- attr_reader :gateway
19
-
20
- # The optional URI
21
- #
22
- # @api public
23
- attr_reader :uri
24
-
25
- # Gateway instance used in lint tests
26
- #
27
- # @api private
28
- attr_reader :gateway_instance
29
-
30
- # Create a gateway linter
31
- #
32
- # @param [Symbol] identifier
33
- # @param [Class] gateway
34
- # @param [String] uri optional
35
- def initialize(identifier, gateway, uri = nil)
36
- @identifier = identifier
37
- @gateway = gateway
38
- @uri = uri
39
- @gateway_instance = setup_gateway_instance
40
- end
41
-
42
- # Lint: Ensure that +gateway+ setups up its instance
43
- #
44
- # @api public
45
- def lint_gateway_setup
46
- return if gateway_instance.instance_of? gateway
47
-
48
- complain <<-STRING
49
- #{gateway}.setup must return a gateway instance but
50
- returned #{gateway_instance.inspect}
51
- STRING
52
- end
53
-
54
- # Lint: Ensure that +gateway_instance+ responds to +[]+
55
- #
56
- # @api public
57
- def lint_dataset_reader
58
- return if gateway_instance.respond_to? :[]
59
-
60
- complain "#{gateway_instance} must respond to []"
61
- end
62
-
63
- # Lint: Ensure that +gateway_instance+ responds to +dataset?+
64
- #
65
- # @api public
66
- def lint_dataset_predicate
67
- return if gateway_instance.respond_to? :dataset?
68
-
69
- complain "#{gateway_instance} must respond to dataset?"
70
- end
71
-
72
- # Lint: Ensure +gateway_instance+ supports +transaction+ interface
73
- #
74
- # @api public
75
- def lint_transaction_support
76
- result = gateway_instance.transaction { 1 }
77
-
78
- if result != 1
79
- complain "#{gateway_instance} must return the result of a transaction block"
80
- end
81
-
82
- gateway_instance.transaction do |t|
83
- t.rollback!
84
-
85
- complain "#{gateway_instance} must interrupt a transaction on rollback"
86
- end
87
- end
88
-
89
- # Lint: Ensure +gateway_instance+ returns adapter name
90
- def lint_adapter_reader
91
- if gateway_instance.adapter != identifier
92
- complain "#{gateway_instance} must have the adapter identifier set to #{identifier.inspect}"
93
- end
94
- rescue MissingAdapterIdentifierError
95
- complain "#{gateway_instance} is missing the adapter identifier"
96
- end
97
-
98
- private
99
-
100
- # Setup gateway instance
101
- #
102
- # @api private
103
- def setup_gateway_instance
104
- if uri
105
- ROM::Gateway.setup(identifier, uri)
106
- else
107
- ROM::Gateway.setup(identifier)
108
- end
109
- end
110
-
111
- # Run Gateway#disconnect
112
- #
113
- # @api private
114
- def after_lint
115
- super
116
- gateway_instance.disconnect
117
- end
118
- end
119
- end
120
- end