rom-core 5.1.2 → 5.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rom/array_dataset.rb +4 -4
  3. data/lib/rom/association_set.rb +2 -3
  4. data/lib/rom/associations/definitions/abstract.rb +2 -2
  5. data/lib/rom/associations/many_to_many.rb +1 -0
  6. data/lib/rom/attribute.rb +5 -4
  7. data/lib/rom/auto_curry.rb +2 -0
  8. data/lib/rom/command.rb +6 -6
  9. data/lib/rom/command_compiler.rb +5 -7
  10. data/lib/rom/commands/class_interface.rb +7 -7
  11. data/lib/rom/commands/composite.rb +1 -1
  12. data/lib/rom/commands/graph/input_evaluator.rb +1 -1
  13. data/lib/rom/commands/lazy.rb +2 -1
  14. data/lib/rom/commands/lazy/create.rb +1 -1
  15. data/lib/rom/commands/lazy/update.rb +3 -3
  16. data/lib/rom/configuration.rb +5 -5
  17. data/lib/rom/configuration_dsl/relation.rb +1 -1
  18. data/lib/rom/constants.rb +1 -1
  19. data/lib/rom/core/version.rb +1 -1
  20. data/lib/rom/data_proxy.rb +3 -2
  21. data/lib/rom/enumerable_dataset.rb +4 -4
  22. data/lib/rom/environment.rb +0 -1
  23. data/lib/rom/header/attribute.rb +2 -4
  24. data/lib/rom/initializer.rb +9 -7
  25. data/lib/rom/lint/gateway.rb +1 -3
  26. data/lib/rom/lint/linter.rb +3 -4
  27. data/lib/rom/lint/spec.rb +2 -2
  28. data/lib/rom/mapper.rb +4 -3
  29. data/lib/rom/mapper/attribute_dsl.rb +5 -5
  30. data/lib/rom/mapper/dsl.rb +2 -5
  31. data/lib/rom/mapper/model_dsl.rb +2 -1
  32. data/lib/rom/mapper_compiler.rb +2 -1
  33. data/lib/rom/mapper_registry.rb +3 -3
  34. data/lib/rom/memory/dataset.rb +4 -3
  35. data/lib/rom/pipeline.rb +3 -1
  36. data/lib/rom/plugin.rb +3 -3
  37. data/lib/rom/plugin_registry.rb +1 -1
  38. data/lib/rom/plugins/command/schema.rb +2 -2
  39. data/lib/rom/plugins/relation/instrumentation.rb +1 -1
  40. data/lib/rom/plugins/relation/registry_reader.rb +4 -3
  41. data/lib/rom/plugins/schema/timestamps.rb +4 -6
  42. data/lib/rom/processor.rb +1 -1
  43. data/lib/rom/processor/transproc.rb +16 -19
  44. data/lib/rom/registry.rb +17 -12
  45. data/lib/rom/relation.rb +6 -6
  46. data/lib/rom/relation/class_interface.rb +9 -8
  47. data/lib/rom/relation/curried.rb +3 -2
  48. data/lib/rom/relation/loaded.rb +1 -0
  49. data/lib/rom/relation/materializable.rb +1 -0
  50. data/lib/rom/relation/name.rb +1 -1
  51. data/lib/rom/relation_registry.rb +1 -1
  52. data/lib/rom/schema.rb +22 -22
  53. data/lib/rom/schema/associations_dsl.rb +17 -17
  54. data/lib/rom/schema/dsl.rb +6 -6
  55. data/lib/rom/schema/inferrer.rb +2 -4
  56. data/lib/rom/setup.rb +2 -2
  57. data/lib/rom/setup/auto_registration.rb +1 -1
  58. data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
  59. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -4
  60. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +1 -1
  61. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +1 -1
  62. data/lib/rom/setup/finalize/finalize_commands.rb +7 -4
  63. data/lib/rom/setup/finalize/finalize_mappers.rb +9 -8
  64. data/lib/rom/setup/finalize/finalize_relations.rb +2 -2
  65. data/lib/rom/struct.rb +1 -1
  66. data/lib/rom/struct_compiler.rb +6 -5
  67. data/lib/rom/support/memoizable.rb +3 -2
  68. data/lib/rom/transaction.rb +1 -1
  69. data/lib/rom/transformer.rb +1 -0
  70. metadata +3 -3
@@ -46,8 +46,8 @@ module ROM
46
46
  # @return [Setup]
47
47
  #
48
48
  # @api public
49
- def auto_registration(directory, options = {})
50
- auto_registration = AutoRegistration.new(directory, options)
49
+ def auto_registration(directory, **options)
50
+ auto_registration = AutoRegistration.new(directory, **options)
51
51
  auto_registration.relations.map { |r| register_relation(r) }
52
52
  auto_registration.commands.map { |r| register_command(r) }
53
53
  auto_registration.mappers.map { |r| register_mapper(r) }
@@ -43,7 +43,7 @@ module ROM
43
43
 
44
44
  # @!attribute [r] globs
45
45
  # @return [Hash] File globbing functions for each component dir
46
- option :globs, default: -> {
46
+ option :globs, default: lambda {
47
47
  Hash[
48
48
  component_dirs.map { |component, path|
49
49
  [component, directory.join("#{path}/**/*.rb")]
@@ -13,7 +13,7 @@ module ROM
13
13
 
14
14
  PathnameType = Types.Instance(Pathname)
15
15
 
16
- EXTENSION_REGEX = /\.rb\z/
16
+ EXTENSION_REGEX = /\.rb\z/.freeze
17
17
 
18
18
  # @!attribute [r] file
19
19
  # @return [String] Name of a component file
@@ -32,7 +32,7 @@ module ROM
32
32
  attempted = []
33
33
 
34
34
  potential.map do |path|
35
- const_fragment = path.join("::")
35
+ const_fragment = path.join('::')
36
36
 
37
37
  constant = "#{namespace}::#{const_fragment}"
38
38
 
@@ -54,8 +54,8 @@ module ROM
54
54
 
55
55
  # @api private
56
56
  def name_error_message(attempted)
57
- "required file does not define expected constant name; either " \
58
- "register your constant explicitly of try following the path" \
57
+ 'required file does not define expected constant name; either ' \
58
+ 'register your constant explicitly of try following the path' \
59
59
  "naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n"
60
60
  end
61
61
 
@@ -76,7 +76,7 @@ module ROM
76
76
 
77
77
  # @api private
78
78
  def file_path
79
- File.dirname(file).split("/") - directory.to_s.split("/")
79
+ File.dirname(file).split('/') - directory.to_s.split('/')
80
80
  end
81
81
  end
82
82
  end
@@ -25,7 +25,7 @@ module ROM
25
25
  # @api private
26
26
  def call
27
27
  Inflector.camelize(
28
- file.sub(/^#{directory}\/#{entity}\//, '').sub(EXTENSION_REGEX, '')
28
+ file.sub(%r{^#{directory}/#{entity}/}, '').sub(EXTENSION_REGEX, '')
29
29
  )
30
30
  end
31
31
  end
@@ -21,7 +21,7 @@ module ROM
21
21
  # @api private
22
22
  def call
23
23
  Inflector.camelize(
24
- file.sub(/^#{directory.dirname}\//, '').sub(EXTENSION_REGEX, '')
24
+ file.sub(%r{^#{directory.dirname}/}, '').sub(EXTENSION_REGEX, '')
25
25
  )
26
26
  end
27
27
  end
@@ -41,13 +41,16 @@ module ROM
41
41
  klass.build(relation)
42
42
  end
43
43
 
44
- registry = Registry.new({})
44
+ registry = Registry.new
45
45
  compiler = CommandCompiler.new(@gateways, @relations, registry, notifications)
46
46
 
47
47
  @relations.each do |(name, relation)|
48
- commands.
49
- select { |c| c.relation.name == relation.name }.
50
- each { |c| relation.commands.elements[c.class.register_as || c.class.default_name] = c }
48
+ rel_commands = commands.select { |c| c.relation.name == relation.name }
49
+
50
+ rel_commands.each do |command|
51
+ identifier = command.class.register_as || command.class.default_name
52
+ relation.commands.elements[identifier] = command
53
+ end
51
54
 
52
55
  relation.commands.set_compiler(compiler)
53
56
  relation.commands.set_mappers(relation.mappers)
@@ -14,10 +14,10 @@ module ROM
14
14
 
15
15
  check_duplicate_registered_mappers
16
16
 
17
- @registry_hash = [@mapper_classes.map(&:base_relation) + @mapper_objects.keys].
18
- flatten.
19
- uniq.
20
- each_with_object({}) { |n, h| h[n] = {} }
17
+ @registry_hash = [@mapper_classes.map(&:base_relation) + @mapper_objects.keys]
18
+ .flatten
19
+ .uniq
20
+ .each_with_object({}) { |n, h| h[n] = {} }
21
21
  end
22
22
 
23
23
  # @api private
@@ -40,8 +40,9 @@ module ROM
40
40
  private
41
41
 
42
42
  def check_duplicate_registered_mappers
43
- mapper_relation_register = mapper_classes.map {|mapper_class| [mapper_class.relation, mapper_class.register_as].compact }
43
+ mapper_relation_register = mapper_classes.map { |mapper_class| [mapper_class.relation, mapper_class.register_as].compact }
44
44
  return if mapper_relation_register.uniq.count == mapper_classes.count
45
+
45
46
  mapper_relation_register.select { |relation_register_as| mapper_relation_register.count(relation_register_as) > 1 }
46
47
  .uniq
47
48
  .each do |duplicated_mappers|
@@ -52,9 +53,9 @@ module ROM
52
53
  end
53
54
 
54
55
  def build_mappers(relation_name)
55
- mapper_classes.
56
- select { |klass| klass.base_relation == relation_name }.
57
- each_with_object({}) { |klass, h| h[klass.register_as || klass.relation] = klass.build }
56
+ mapper_classes
57
+ .select { |klass| klass.base_relation == relation_name }
58
+ .each_with_object({}) { |klass, h| h[klass.register_as || klass.relation] = klass.build }
58
59
  end
59
60
  end
60
61
  end
@@ -43,7 +43,7 @@ module ROM
43
43
  "Relation with name #{key.inspect} registered more than once"
44
44
  end
45
45
 
46
- klass.use(:registry_reader, relation_names)
46
+ klass.use(:registry_reader, relations: relation_names)
47
47
 
48
48
  notifications.trigger('configuration.relations.class.ready', relation: klass, adapter: klass.adapter)
49
49
 
@@ -105,7 +105,7 @@ module ROM
105
105
 
106
106
  options = { __registry__: registry, mappers: mapper_registry(rel_key, klass), schema: schema, **plugin_options }
107
107
 
108
- klass.new(dataset, options)
108
+ klass.new(dataset, **options)
109
109
  end
110
110
 
111
111
  # @api private
@@ -102,7 +102,7 @@ module ROM
102
102
  def method_missing(*)
103
103
  super
104
104
  rescue NameError => error
105
- raise MissingAttribute.new { "#{ error.message } (attribute not loaded?)" }
105
+ raise MissingAttribute.new { "#{error.message} (attribute not loaded?)" }
106
106
  end
107
107
  end
108
108
  end
@@ -20,10 +20,11 @@ module ROM
20
20
  option :cache, default: -> { Cache.new }
21
21
 
22
22
  # @api private
23
- def initialize(*args)
23
+ def initialize(*)
24
24
  super
25
25
  @cache = cache.namespaced(:structs)
26
26
  end
27
+ ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
27
28
 
28
29
  # Build a struct class based on relation header ast
29
30
  #
@@ -84,7 +85,7 @@ module ROM
84
85
 
85
86
  # @api private
86
87
  def visit_constrained(node)
87
- definition, _ = node
88
+ definition, = node
88
89
 
89
90
  visit(definition)
90
91
  end
@@ -97,9 +98,9 @@ module ROM
97
98
 
98
99
  # @api private
99
100
  def build_class(name, parent, ns, &block)
100
- Dry::Core::ClassBuilder.
101
- new(name: class_name(name), parent: parent, namespace: ns).
102
- call(&block)
101
+ Dry::Core::ClassBuilder
102
+ .new(name: class_name(name), parent: parent, namespace: ns)
103
+ .call(&block)
103
104
  end
104
105
 
105
106
  # @api private
@@ -3,7 +3,7 @@
3
3
  module ROM
4
4
  # @api private
5
5
  module Memoizable
6
- MEMOIZED_HASH = {}
6
+ MEMOIZED_HASH = {}.freeze
7
7
 
8
8
  module ClassInterface
9
9
  # @api private
@@ -16,6 +16,7 @@ module ROM
16
16
  obj.instance_variable_set(:'@__memoized__', MEMOIZED_HASH.dup)
17
17
  obj
18
18
  end
19
+ ruby2_keywords(:new) if respond_to?(:ruby2_keywords, true)
19
20
  end
20
21
 
21
22
  def self.included(klass)
@@ -44,7 +45,7 @@ module ROM
44
45
  names.each do |name|
45
46
  meth = klass.instance_method(name)
46
47
 
47
- if meth.parameters.size > 0
48
+ if !meth.parameters.empty?
48
49
  define_method(name) do |*args|
49
50
  __memoized__[:"#{name}_#{args.hash}"] ||= super(*args)
50
51
  end
@@ -7,7 +7,7 @@ module ROM
7
7
  Rollback = Class.new(StandardError)
8
8
 
9
9
  # @api private
10
- def run(opts = EMPTY_HASH)
10
+ def run(_opts = EMPTY_HASH)
11
11
  yield(self)
12
12
  rescue Rollback
13
13
  # noop
@@ -53,6 +53,7 @@ module ROM
53
53
  # @api public
54
54
  def self.relation(name = Undefined, options = EMPTY_HASH)
55
55
  return @relation if name.equal?(Undefined) && defined?(@relation)
56
+
56
57
  register_as(options.fetch(:as, name))
57
58
  @relation = name
58
59
  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: 5.1.2
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2020-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -342,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
342
342
  - !ruby/object:Gem::Version
343
343
  version: '0'
344
344
  requirements: []
345
- rubygems_version: 3.0.3
345
+ rubygems_version: 3.1.0.pre3
346
346
  signing_key:
347
347
  specification_version: 4
348
348
  summary: Ruby Object Mapper