rom-core 5.3.2 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rom/array_dataset.rb +5 -5
  3. data/lib/rom/association_set.rb +1 -2
  4. data/lib/rom/associations/definitions/abstract.rb +5 -3
  5. data/lib/rom/associations/many_to_many.rb +1 -2
  6. data/lib/rom/attribute.rb +15 -37
  7. data/lib/rom/auto_curry.rb +34 -23
  8. data/lib/rom/cache.rb +9 -21
  9. data/lib/rom/command.rb +19 -37
  10. data/lib/rom/command_compiler.rb +12 -14
  11. data/lib/rom/command_proxy.rb +6 -10
  12. data/lib/rom/command_registry.rb +4 -8
  13. data/lib/rom/commands/class_interface.rb +20 -20
  14. data/lib/rom/commands/composite.rb +3 -0
  15. data/lib/rom/commands/graph/class_interface.rb +3 -1
  16. data/lib/rom/commands/graph/input_evaluator.rb +3 -1
  17. data/lib/rom/commands/graph.rb +3 -0
  18. data/lib/rom/commands/lazy/create.rb +2 -0
  19. data/lib/rom/commands/lazy/update.rb +2 -0
  20. data/lib/rom/commands/lazy.rb +2 -3
  21. data/lib/rom/configuration.rb +14 -16
  22. data/lib/rom/configuration_dsl/command.rb +2 -2
  23. data/lib/rom/configuration_dsl/command_dsl.rb +9 -5
  24. data/lib/rom/configuration_dsl/mapper_dsl.rb +12 -3
  25. data/lib/rom/configuration_dsl/relation.rb +4 -2
  26. data/lib/rom/configuration_dsl.rb +8 -10
  27. data/lib/rom/constants.rb +26 -26
  28. data/lib/rom/container.rb +15 -15
  29. data/lib/rom/core/version.rb +1 -1
  30. data/lib/rom/core.rb +0 -1
  31. data/lib/rom/create_container.rb +3 -5
  32. data/lib/rom/data_proxy.rb +13 -15
  33. data/lib/rom/enumerable_dataset.rb +6 -6
  34. data/lib/rom/environment.rb +5 -5
  35. data/lib/rom/gateway.rb +4 -12
  36. data/lib/rom/global/plugin_dsl.rb +4 -4
  37. data/lib/rom/global.rb +2 -2
  38. data/lib/rom/header/attribute.rb +1 -1
  39. data/lib/rom/header.rb +13 -35
  40. data/lib/rom/initializer.rb +11 -15
  41. data/lib/rom/lint/enumerable_dataset.rb +2 -1
  42. data/lib/rom/lint/gateway.rb +3 -1
  43. data/lib/rom/lint/linter.rb +2 -2
  44. data/lib/rom/lint/test.rb +4 -6
  45. data/lib/rom/mapper/attribute_dsl.rb +39 -27
  46. data/lib/rom/mapper/builder.rb +2 -2
  47. data/lib/rom/mapper/dsl.rb +2 -3
  48. data/lib/rom/mapper/model_dsl.rb +5 -1
  49. data/lib/rom/mapper.rb +2 -4
  50. data/lib/rom/mapper_compiler.rb +3 -2
  51. data/lib/rom/mapper_registry.rb +2 -4
  52. data/lib/rom/memory/commands.rb +1 -1
  53. data/lib/rom/memory/dataset.rb +7 -5
  54. data/lib/rom/memory/gateway.rb +1 -0
  55. data/lib/rom/model_builder.rb +14 -14
  56. data/lib/rom/open_struct.rb +1 -1
  57. data/lib/rom/pipeline.rb +6 -15
  58. data/lib/rom/plugin_registry.rb +4 -10
  59. data/lib/rom/plugins/command/timestamps.rb +9 -5
  60. data/lib/rom/plugins/relation/instrumentation.rb +7 -2
  61. data/lib/rom/plugins/relation/registry_reader.rb +3 -15
  62. data/lib/rom/plugins.rb +1 -3
  63. data/lib/rom/processor/transproc.rb +14 -4
  64. data/lib/rom/processor.rb +1 -0
  65. data/lib/rom/registry.rb +20 -29
  66. data/lib/rom/relation/class_interface.rb +18 -16
  67. data/lib/rom/relation/combined.rb +7 -4
  68. data/lib/rom/relation/composite.rb +2 -6
  69. data/lib/rom/relation/curried.rb +12 -11
  70. data/lib/rom/relation/graph.rb +4 -12
  71. data/lib/rom/relation/loaded.rb +8 -16
  72. data/lib/rom/relation/materializable.rb +6 -14
  73. data/lib/rom/relation/name.rb +5 -14
  74. data/lib/rom/relation/view_dsl.rb +7 -9
  75. data/lib/rom/relation/wrap.rb +3 -9
  76. data/lib/rom/relation.rb +39 -81
  77. data/lib/rom/schema/associations_dsl.rb +4 -8
  78. data/lib/rom/schema/dsl.rb +14 -13
  79. data/lib/rom/schema/inferrer.rb +5 -3
  80. data/lib/rom/schema.rb +27 -41
  81. data/lib/rom/setup/auto_registration.rb +4 -6
  82. data/lib/rom/setup/auto_registration_strategies/base.rb +1 -1
  83. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -8
  84. data/lib/rom/setup/finalize/finalize_commands.rb +3 -0
  85. data/lib/rom/setup/finalize/finalize_mappers.rb +16 -14
  86. data/lib/rom/setup/finalize/finalize_relations.rb +30 -4
  87. data/lib/rom/setup/finalize.rb +17 -3
  88. data/lib/rom/setup.rb +5 -4
  89. data/lib/rom/struct.rb +20 -18
  90. data/lib/rom/struct_compiler.rb +4 -7
  91. data/lib/rom/support/configurable.rb +10 -20
  92. data/lib/rom/support/memoizable.rb +10 -9
  93. data/lib/rom/support/notifications.rb +4 -8
  94. data/lib/rom/transaction.rb +2 -4
  95. data/lib/rom/transformer.rb +6 -10
  96. data/lib/rom/types.rb +3 -6
  97. metadata +15 -57
@@ -55,14 +55,12 @@ module ROM
55
55
  # @api private
56
56
  def name_error_message(attempted)
57
57
  'required file does not define expected constant name; either ' \
58
- 'register your constant explicitly of try following the path' \
59
- "naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n"
58
+ 'register your constant explicitly of try following the path' \
59
+ "naming convention like:\n\n\t- #{attempted.join("\n\t- ")}\n"
60
60
  end
61
61
 
62
62
  # @api private
63
- def filename
64
- Pathname(file).basename('.rb')
65
- end
63
+ def filename = Pathname(file).basename('.rb')
66
64
 
67
65
  # @api private
68
66
  def ns_const
@@ -70,9 +68,7 @@ module ROM
70
68
  end
71
69
 
72
70
  # @api private
73
- def path_arr
74
- file_path << filename
75
- end
71
+ def path_arr = file_path << filename
76
72
 
77
73
  # @api private
78
74
  def file_path
@@ -26,6 +26,8 @@ module ROM
26
26
  # @return [Hash]
27
27
  #
28
28
  # @api private
29
+ #
30
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
29
31
  def run!
30
32
  commands = @command_classes.map do |klass|
31
33
  relation = @relations[klass.relation]
@@ -60,6 +62,7 @@ module ROM
60
62
 
61
63
  registry
62
64
  end
65
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
63
66
  end
64
67
  end
65
68
  end
@@ -5,7 +5,9 @@ require 'rom/registry'
5
5
  module ROM
6
6
  class Finalize
7
7
  class FinalizeMappers
8
- attr_reader :mapper_classes, :mapper_objects, :registry_hash
8
+ attr_reader :mapper_classes
9
+ attr_reader :mapper_objects
10
+ attr_reader :registry_hash
9
11
 
10
12
  # @api private
11
13
  def initialize(mapper_classes, mapper_objects)
@@ -17,21 +19,21 @@ module ROM
17
19
  @registry_hash = [@mapper_classes.map(&:base_relation) + @mapper_objects.keys]
18
20
  .flatten
19
21
  .uniq
20
- .each_with_object({}) { |n, h| h[n] = {} }
22
+ .to_h { [_1, {}] }
21
23
  end
22
24
 
23
25
  # @api private
24
26
  def run!
25
27
  cache = Cache.new
26
28
 
27
- mappers = registry_hash.each_with_object({}) do |(relation_name, relation_mappers), h|
29
+ mappers = registry_hash.to_h do |relation_name, relation_mappers|
28
30
  relation_mappers.update(build_mappers(relation_name))
29
31
 
30
32
  if mapper_objects.key?(relation_name)
31
33
  relation_mappers.update(mapper_objects[relation_name])
32
34
  end
33
35
 
34
- h[relation_name] = MapperRegistry.new(relation_mappers, cache: cache)
36
+ [relation_name, MapperRegistry.new(relation_mappers, cache: cache)]
35
37
  end
36
38
 
37
39
  Registry.new(mappers, cache: cache)
@@ -40,22 +42,22 @@ module ROM
40
42
  private
41
43
 
42
44
  def check_duplicate_registered_mappers
43
- mapper_relation_register = mapper_classes.map { |mapper_class| [mapper_class.relation, mapper_class.register_as].compact }
44
- return if mapper_relation_register.uniq.count == mapper_classes.count
45
+ duplicates = mapper_classes.map { [_1.relation, _1.register_as] }.tally.select { _2 > 1 }
45
46
 
46
- mapper_relation_register.select { |relation_register_as| mapper_relation_register.count(relation_register_as) > 1 }
47
- .uniq
48
- .each do |duplicated_mappers|
49
- raise MapperAlreadyDefinedError,
50
- "Mapper with `register_as #{duplicated_mappers.last.inspect}` registered more " \
51
- "than once for relation #{duplicated_mappers.first.inspect}"
52
- end
47
+ case duplicates.first
48
+ in [rel, as], _
49
+ raise MapperAlreadyDefinedError,
50
+ "Mapper with `register_as #{as.inspect}` registered more " \
51
+ "than once for relation #{rel.inspect}"
52
+ else
53
+ nil
54
+ end
53
55
  end
54
56
 
55
57
  def build_mappers(relation_name)
56
58
  mapper_classes
57
59
  .select { |klass| klass.base_relation == relation_name }
58
- .each_with_object({}) { |klass, h| h[klass.register_as || klass.relation] = klass.build }
60
+ .to_h { |k| [k.register_as || k.relation, k.build] }
59
61
  end
60
62
  end
61
63
  end
@@ -9,6 +9,16 @@ module ROM
9
9
  class FinalizeRelations
10
10
  attr_reader :notifications
11
11
 
12
+ class RegistryReaders < ::Module
13
+ def initialize(relations)
14
+ super()
15
+
16
+ relations.each do |name|
17
+ define_method(name) { __registry__[name] }
18
+ end
19
+ end
20
+ end
21
+
12
22
  # Build relation registry of specified descendant classes
13
23
  #
14
24
  # This is used by the setup
@@ -28,8 +38,11 @@ module ROM
28
38
  # @return [Hash]
29
39
  #
30
40
  # @api private
41
+ #
42
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
31
43
  def run!
32
44
  relation_registry = RelationRegistry.new do |registry, relations|
45
+ registry_readers = RegistryReaders.new(relation_names)
33
46
  @relation_classes.each do |klass|
34
47
  unless klass.adapter
35
48
  raise MissingAdapterIdentifierError,
@@ -43,14 +56,18 @@ module ROM
43
56
  "Relation with name #{key.inspect} registered more than once"
44
57
  end
45
58
 
46
- klass.use(:registry_reader, relations: relation_names)
59
+ klass.use(:registry_reader, readers: registry_readers)
47
60
 
48
- notifications.trigger('configuration.relations.class.ready', relation: klass, adapter: klass.adapter)
61
+ notifications.trigger(
62
+ 'configuration.relations.class.ready',
63
+ relation: klass,
64
+ adapter: klass.adapter
65
+ )
49
66
 
50
67
  relations[key] = build_relation(klass, registry)
51
68
  end
52
69
 
53
- registry.each do |_, relation|
70
+ registry.each_value do |relation|
54
71
  notifications.trigger(
55
72
  'configuration.relations.object.registered',
56
73
  relation: relation, registry: registry
@@ -64,10 +81,13 @@ module ROM
64
81
 
65
82
  relation_registry
66
83
  end
84
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
67
85
 
68
86
  # @return [ROM::Relation]
69
87
  #
70
88
  # @api private
89
+ #
90
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
71
91
  def build_relation(klass, registry)
72
92
  # TODO: raise a meaningful error here and add spec covering the case
73
93
  # where klass' gateway points to non-existant repo
@@ -103,10 +123,16 @@ module ROM
103
123
  dataset: dataset, relation: klass, adapter: klass.adapter
104
124
  )
105
125
 
106
- options = { __registry__: registry, mappers: mapper_registry(rel_key, klass), schema: schema, **plugin_options }
126
+ options = {
127
+ __registry__: registry,
128
+ mappers: mapper_registry(rel_key, klass),
129
+ schema: schema,
130
+ **plugin_options
131
+ }
107
132
 
108
133
  klass.new(dataset, **options)
109
134
  end
135
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
110
136
 
111
137
  # @api private
112
138
  def mapper_registry(rel_key, rel_class)
@@ -22,9 +22,23 @@ module ROM
22
22
  #
23
23
  # @private
24
24
  class Finalize
25
- attr_reader :gateways, :repo_adapter,
26
- :relation_classes, :mapper_classes, :mapper_objects,
27
- :command_classes, :plugins, :config, :notifications
25
+ attr_reader :gateways
26
+
27
+ attr_reader :repo_adapter
28
+
29
+ attr_reader :relation_classes
30
+
31
+ attr_reader :mapper_classes
32
+
33
+ attr_reader :mapper_objects
34
+
35
+ attr_reader :command_classes
36
+
37
+ attr_reader :plugins
38
+
39
+ attr_reader :config
40
+
41
+ attr_reader :notifications
28
42
 
29
43
  # @api private
30
44
  def initialize(options)
data/lib/rom/setup.rb CHANGED
@@ -41,16 +41,17 @@ module ROM
41
41
  #
42
42
  # @param [String, Pathname] directory The root path to components
43
43
  # @param [Hash] options
44
- # @option options [Boolean, String] :namespace Enable/disable namespace or provide a custom namespace name
44
+ # @option options [Boolean, String] :namespace Enable/disable
45
+ # namespace or provide a custom namespace name
45
46
  #
46
47
  # @return [Setup]
47
48
  #
48
49
  # @api public
49
50
  def auto_registration(directory, **options)
50
51
  auto_registration = AutoRegistration.new(directory, **options)
51
- auto_registration.relations.map { |r| register_relation(r) }
52
- auto_registration.commands.map { |r| register_command(r) }
53
- auto_registration.mappers.map { |r| register_mapper(r) }
52
+ auto_registration.relations.each { |r| register_relation(r) }
53
+ auto_registration.commands.each { |r| register_command(r) }
54
+ auto_registration.mappers.each { |r| register_mapper(r) }
54
55
  self
55
56
  end
56
57
 
data/lib/rom/struct.rb CHANGED
@@ -15,9 +15,10 @@ module ROM
15
15
  # about attribute types returned from relations, thus can be introspected to build
16
16
  # additional functionality when desired.
17
17
  #
18
- # There is a caveat you should know about when working with structs. Struct classes
19
- # have names but at the same time they're anonymous, i.e. you can't get the User struct class
20
- # with ROM::Struct::User. ROM will create as many struct classes for User as needed,
18
+ # *NOTE*: There is a caveat you should know about when working with ROM structs.
19
+ # Struct classes have names but at the same time they're anonymous,
20
+ # i.e. you can't get the User struct class with ROM::Struct::User.
21
+ # ROM will create as many struct classes for User as needed,
21
22
  # they all will have the same name and ROM::Struct::User will be the common parent class for
22
23
  # them. Combined with the ability to provide your own namespace for structs this enables to
23
24
  # pre-define the parent class.
@@ -28,6 +29,11 @@ module ROM
28
29
  # primary_key :id
29
30
  # column :name, String
30
31
  # end
32
+ #
33
+ # conf.relation(:users) do
34
+ # schema(infer: true)
35
+ # auto_struct true
36
+ # end
31
37
  # end
32
38
  #
33
39
  # class UserRepo < ROM::Repository[:users]
@@ -41,11 +47,12 @@ module ROM
41
47
  #
42
48
  # # see struct's schema attributes
43
49
  #
44
- # # model.schema.key(:id)
50
+ # model.schema.key(:id)
45
51
  # # => #<Dry::Types[id: Nominal<Integer meta={primary_key: true, source: :users}>]>
46
52
  #
47
53
  # model.schema[:name]
48
- # # => #<Dry::Types[name: Sum<Nominal<NilClass> | Nominal<String> meta={source: :users}>]>
54
+ # # => #<Dry::Types[name: Sum<Nominal<NilClass> |
55
+ # # Nominal<String meta={source: :users}> meta={source: :users}>]>
49
56
  #
50
57
  # @example passing a namespace with an existing parent class
51
58
  # module Entities
@@ -61,6 +68,7 @@ module ROM
61
68
  # end
62
69
  #
63
70
  # user_repo = UserRepo.new(rom)
71
+ # user_repo.users.insert(name: "Jane")
64
72
  # user = user_repo.users.by_pk(1).one!
65
73
  # user.name # => "Jane"
66
74
  # user.upcased_name # => "JANE"
@@ -69,16 +77,14 @@ module ROM
69
77
  # @see http://dry-rb.org/gems/dry-types dry-types
70
78
  #
71
79
  # @api public
72
- class Struct < Dry::Struct
73
- MissingAttribute = Class.new(NameError) do
80
+ class Struct < ::Dry::Struct
81
+ MissingAttribute = ::Class.new(::NameError) do
74
82
  def initialize(&block)
75
83
  super
76
84
  @message_proc = block
77
85
  end
78
86
 
79
- def message
80
- @message_proc.call
81
- end
87
+ def message = @message_proc.call
82
88
  end
83
89
 
84
90
  # Return attribute value
@@ -86,21 +92,17 @@ module ROM
86
92
  # @param [Symbol] name The attribute name
87
93
  #
88
94
  # @api public
89
- def fetch(name)
90
- __send__(name)
91
- end
95
+ def fetch(name) = __send__(name)
92
96
 
93
97
  # @api private
94
- def respond_to_missing?(*)
95
- super
96
- end
98
+ def respond_to_missing?(*) = super
97
99
 
98
100
  private
99
101
 
100
102
  def method_missing(*)
101
103
  super
102
- rescue NameError => error
103
- raise MissingAttribute.new { "#{error.message} (attribute not loaded?)" }
104
+ rescue ::NameError => e
105
+ raise(MissingAttribute.new { "#{e.message} (attribute not loaded?)" })
104
106
  end
105
107
  end
106
108
  end
@@ -18,11 +18,10 @@ module ROM
18
18
  option :cache, default: -> { Cache.new }
19
19
 
20
20
  # @api private
21
- def initialize(*)
21
+ def initialize(*, **)
22
22
  super
23
23
  @cache = cache.namespaced(:structs)
24
24
  end
25
- ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
26
25
 
27
26
  # Build a struct class based on relation header ast
28
27
  #
@@ -95,15 +94,13 @@ module ROM
95
94
  end
96
95
 
97
96
  # @api private
98
- def build_class(name, parent, ns, &block)
97
+ def build_class(name, parent, ns, &)
99
98
  Dry::Core::ClassBuilder
100
99
  .new(name: class_name(name), parent: parent, namespace: ns)
101
- .call(&block)
100
+ .call(&)
102
101
  end
103
102
 
104
103
  # @api private
105
- def class_name(name)
106
- Inflector.classify(name)
107
- end
104
+ def class_name(name) = Inflector.classify(name)
108
105
  end
109
106
  end
@@ -7,7 +7,7 @@ module ROM
7
7
  # @api private
8
8
  module Configurable
9
9
  class Config
10
- WRITER_REGEXP = /=$/.freeze
10
+ WRITER_REGEXP = /=$/
11
11
 
12
12
  # @!attribute [r] settings
13
13
  # @return [Hash] A hash with defined settings
@@ -23,43 +23,33 @@ module ROM
23
23
  # @return [Mixed]
24
24
  #
25
25
  # @api public
26
- def [](name)
27
- public_send(name)
28
- end
26
+ def [](name) = public_send(name)
29
27
 
30
28
  # @api private
31
- def key?(name)
32
- settings.key?(name)
33
- end
29
+ def key?(name) = settings.key?(name)
34
30
 
35
- def to_hash
36
- settings
37
- end
31
+ def to_hash = settings
38
32
 
39
33
  # @api private
40
- def respond_to_missing?(_name, _include_private = false)
41
- true
42
- end
34
+ def respond_to_missing?(_name, _include_private = false) = true
43
35
 
44
36
  # @api private
45
- def dup
46
- self.class.new(dup_settings(settings))
47
- end
37
+ def dup = self.class.new(dup_settings(settings))
48
38
 
49
39
  private
50
40
 
51
41
  def dup_settings(settings)
52
- settings.each_with_object({}) do |(key, value), new_settings|
42
+ settings.to_h do |key, value|
53
43
  if value.is_a?(self.class)
54
- new_settings[key] = value.dup
44
+ [key, value.dup]
55
45
  else
56
- new_settings[key] = value
46
+ [key, value]
57
47
  end
58
48
  end
59
49
  end
60
50
 
61
51
  # @api private
62
- def method_missing(meth, *args, &_block)
52
+ def method_missing(meth, *args, &)
63
53
  return settings.fetch(meth, nil) if frozen?
64
54
 
65
55
  name = meth.to_s
@@ -11,12 +11,11 @@ module ROM
11
11
  prepend(Memoizer.new(self, names))
12
12
  end
13
13
 
14
- def new(*)
14
+ def new(*, **, &)
15
15
  obj = super
16
- obj.instance_variable_set(:'@__memoized__', MEMOIZED_HASH.dup)
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)
20
19
  end
21
20
 
22
21
  def self.included(klass)
@@ -27,12 +26,14 @@ module ROM
27
26
  attr_reader :__memoized__
28
27
 
29
28
  # @api private
30
- class Memoizer < Module
29
+ class Memoizer < ::Module
31
30
  attr_reader :klass
31
+
32
32
  attr_reader :names
33
33
 
34
34
  # @api private
35
35
  def initialize(klass, names)
36
+ super()
36
37
  @names = names
37
38
  @klass = klass
38
39
  define_memoizable_names!
@@ -45,14 +46,14 @@ module ROM
45
46
  names.each do |name|
46
47
  meth = klass.instance_method(name)
47
48
 
48
- if !meth.parameters.empty?
49
- define_method(name) do |*args|
50
- __memoized__[:"#{name}_#{args.hash}"] ||= super(*args)
51
- end
52
- else
49
+ if meth.parameters.empty?
53
50
  define_method(name) do
54
51
  __memoized__[name] ||= super()
55
52
  end
53
+ else
54
+ define_method(name) do |*args|
55
+ __memoized__[:"#{name}_#{args.hash}"] ||= super(*args)
56
+ end
56
57
  end
57
58
  end
58
59
  end
@@ -36,7 +36,7 @@ module ROM
36
36
  # end
37
37
  #
38
38
  module Notifications
39
- LISTENERS_HASH = Hash.new { |h, k| h[k] = [] }
39
+ LISTENERS_HASH = ::Hash.new { |h, k| h[k] = [] }
40
40
 
41
41
  # Extension used for classes that can trigger events
42
42
  #
@@ -75,7 +75,7 @@ module ROM
75
75
  #
76
76
  # @api public
77
77
  class Event
78
- include Dry::Equalizer(:id, :payload)
78
+ include ::Dry::Equalizer(:id, :payload)
79
79
 
80
80
  # @!attribute [r] id
81
81
  # @return [Symbol] The event identifier
@@ -99,18 +99,14 @@ module ROM
99
99
  # @param [String,Symbol] name
100
100
  #
101
101
  # @api public
102
- def [](name)
103
- @payload.fetch(name)
104
- end
102
+ def [](name) = @payload.fetch(name)
105
103
 
106
104
  # Coerce an event to a hash
107
105
  #
108
106
  # @return [Hash]
109
107
  #
110
108
  # @api public
111
- def to_h
112
- @payload
113
- end
109
+ def to_h = @payload
114
110
  alias_method :to_hash, :to_h
115
111
 
116
112
  # Get or set a payload
@@ -4,7 +4,7 @@ module ROM
4
4
  # @api private
5
5
  class Transaction
6
6
  # @api private
7
- Rollback = Class.new(StandardError)
7
+ Rollback = ::Class.new(::StandardError)
8
8
 
9
9
  # @api private
10
10
  def run(_opts = EMPTY_HASH)
@@ -16,9 +16,7 @@ module ROM
16
16
  # Unconditionally roll back the current transaction
17
17
  #
18
18
  # @api public
19
- def rollback!
20
- raise Rollback
21
- end
19
+ def rollback! = raise(Rollback)
22
20
 
23
21
  # @api private
24
22
  NoOp = Transaction.new.freeze
@@ -9,8 +9,8 @@ module ROM
9
9
  # transformations.
10
10
  #
11
11
  # @api public
12
- class Transformer < Transproc::Transformer[ROM::Processor::Transproc::Functions]
13
- extend Dry::Core::ClassAttributes
12
+ class Transformer < Transproc::Transformer[::ROM::Processor::Transproc::Functions]
13
+ extend ::Dry::Core::ClassAttributes
14
14
 
15
15
  # @!method self.register_as
16
16
  # Get or set registration name
@@ -70,26 +70,22 @@ module ROM
70
70
  # @return [self]
71
71
  #
72
72
  # @api public
73
- def self.map(&block)
73
+ def self.map(&)
74
74
  define! do
75
- map_array(&block)
75
+ map_array(&)
76
76
  end
77
77
  end
78
78
 
79
79
  # This is needed to make transformers compatible with rom setup
80
80
  #
81
81
  # @api private
82
- def self.base_relation
83
- relation
84
- end
82
+ def self.base_relation = relation
85
83
 
86
84
  # Build a mapper instance
87
85
  #
88
86
  # @return [Transformer]
89
87
  #
90
88
  # @api public
91
- def self.build
92
- new
93
- end
89
+ def self.build = new
94
90
  end
95
91
  end
data/lib/rom/types.rb CHANGED
@@ -8,7 +8,6 @@ module ROM
8
8
  #
9
9
  # @api public
10
10
  #
11
- # rubocop:disable Naming/MethodName
12
11
  module Types
13
12
  include Dry::Types(default: :nominal)
14
13
 
@@ -44,11 +43,9 @@ module ROM
44
43
  # @api public
45
44
  def Coercible.JSONHash(symbol_keys: false, type: Types::Hash)
46
45
  Types.Constructor(type) do |value|
47
- begin
48
- ::JSON.parse(value.to_s, symbolize_names: symbol_keys)
49
- rescue ::JSON::ParserError
50
- value
51
- end
46
+ ::JSON.parse(value.to_s, symbolize_names: symbol_keys)
47
+ rescue ::JSON::ParserError
48
+ value
52
49
  end
53
50
  end
54
51