rom-repository 5.3.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rom/repository/class_interface.rb +33 -9
- data/lib/rom/repository/relation_reader.rb +56 -24
- data/lib/rom/repository/root.rb +4 -10
- data/lib/rom/repository/version.rb +1 -1
- data/lib/rom/repository.rb +5 -5
- metadata +11 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1945e400f70ab8fba8b203ab2a5894ff0c3af70dbe55a00bb20ccd33ed0663b8
|
4
|
+
data.tar.gz: 48e96bca0f06806b8cc03a390c3c11ecae6f1b4b05c3ae0c96e0b380c25e27d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42202fc4ee9f6680131f95e990eb8785ad23fd82aa67cedd1ce79249cd8bdb2318b081b31f6efc2f632f18a29d6dd17de7739f848906b997e46457416f3eacd8
|
7
|
+
data.tar.gz: 1ce9298b198da42a05070e5efdc6f426f7fdb0a9107428af9e3031c19296728df9ddb5bf369fb1fbec836740c4d14f6a827c48fa3cae9a83fc33de63be63a174
|
@@ -22,7 +22,14 @@ module ROM
|
|
22
22
|
# @api public
|
23
23
|
def [](name)
|
24
24
|
fetch_or_store(name) do
|
25
|
-
|
25
|
+
base =
|
26
|
+
if self < Repository::Root # rubocop:disable Style/MinMaxComparison
|
27
|
+
self
|
28
|
+
else
|
29
|
+
Repository::Root
|
30
|
+
end
|
31
|
+
|
32
|
+
klass = ::Class.new(base)
|
26
33
|
klass.root(name)
|
27
34
|
klass
|
28
35
|
end
|
@@ -49,12 +56,15 @@ module ROM
|
|
49
56
|
# @option options [Boolean] :auto_struct Enable/Disable auto-struct mapping
|
50
57
|
#
|
51
58
|
# @api public
|
52
|
-
def new(container = nil, **options)
|
59
|
+
def new(container = nil, root: Undefined, **options)
|
53
60
|
container ||= options.fetch(:container)
|
54
61
|
|
55
|
-
unless relation_reader
|
56
|
-
relation_reader
|
57
|
-
|
62
|
+
unless self < relation_reader
|
63
|
+
include relation_reader.new(
|
64
|
+
relations: container.relations.elements.keys,
|
65
|
+
cache: container.cache,
|
66
|
+
root: root
|
67
|
+
)
|
58
68
|
end
|
59
69
|
|
60
70
|
super(**options, container: container)
|
@@ -66,7 +76,7 @@ module ROM
|
|
66
76
|
def inherited(klass)
|
67
77
|
super
|
68
78
|
|
69
|
-
return if self === Repository
|
79
|
+
return if self === Repository # rubocop:disable Style/CaseEquality
|
70
80
|
|
71
81
|
klass.extend(::Dry::Core::Cache)
|
72
82
|
klass.commands(*commands)
|
@@ -96,6 +106,8 @@ module ROM
|
|
96
106
|
# @return [Array<Symbol>] A list of defined command names
|
97
107
|
#
|
98
108
|
# @api public
|
109
|
+
#
|
110
|
+
# rubocop:disable Metrics/MethodLength
|
99
111
|
def commands(*names, mapper: nil, use: nil, plugins_options: EMPTY_HASH, **opts)
|
100
112
|
if names.any? || opts.any?
|
101
113
|
@commands = names + opts.to_a
|
@@ -103,16 +115,28 @@ module ROM
|
|
103
115
|
@commands.each do |spec|
|
104
116
|
type, *view = Array(spec).flatten
|
105
117
|
|
106
|
-
if
|
107
|
-
|
118
|
+
if view.empty?
|
119
|
+
define_command_method(
|
120
|
+
type,
|
121
|
+
mapper: mapper,
|
122
|
+
use: use,
|
123
|
+
plugins_options: plugins_options
|
124
|
+
)
|
108
125
|
else
|
109
|
-
|
126
|
+
define_restricted_command_method(
|
127
|
+
type,
|
128
|
+
view,
|
129
|
+
mapper: mapper,
|
130
|
+
use: use,
|
131
|
+
plugins_options: plugins_options
|
132
|
+
)
|
110
133
|
end
|
111
134
|
end
|
112
135
|
else
|
113
136
|
@commands ||= []
|
114
137
|
end
|
115
138
|
end
|
139
|
+
# rubocop:enable Metrics/MethodLength
|
116
140
|
|
117
141
|
# @api public
|
118
142
|
def use(plugin, **options)
|
@@ -3,44 +3,76 @@
|
|
3
3
|
module ROM
|
4
4
|
class Repository
|
5
5
|
# @api private
|
6
|
-
class RelationReader < Module
|
7
|
-
# @api private
|
8
|
-
attr_reader :klass
|
9
|
-
|
10
|
-
# @api private
|
11
|
-
attr_reader :relations
|
12
|
-
|
6
|
+
class RelationReader < ::Module
|
13
7
|
module InstanceMethods
|
8
|
+
private
|
9
|
+
|
14
10
|
# @api private
|
15
|
-
def
|
11
|
+
def prepare_relation(name, **)
|
16
12
|
container
|
17
13
|
.relations[name]
|
18
|
-
.with(
|
19
|
-
|
14
|
+
.with(
|
15
|
+
auto_struct: auto_struct,
|
16
|
+
struct_namespace: struct_namespace
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
def relation_reader(cache, ...)
|
22
|
+
cache_key = relation_cache_key(...)
|
23
|
+
cache.fetch_or_store(*cache_key) { prepare_relation(...) }
|
24
|
+
end
|
25
|
+
|
26
|
+
# @api private
|
27
|
+
def relation_cache_key(name, **)
|
28
|
+
[name, auto_struct, struct_namespace]
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
23
32
|
# @api private
|
24
|
-
|
25
|
-
@
|
26
|
-
|
27
|
-
|
33
|
+
class Readers < ::Module
|
34
|
+
# @api private
|
35
|
+
attr_reader :cache
|
36
|
+
|
37
|
+
def initialize(relations)
|
38
|
+
super()
|
39
|
+
|
40
|
+
include InstanceMethods
|
41
|
+
|
42
|
+
define_readers(relations)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @api private
|
46
|
+
def define_readers(relations)
|
47
|
+
cache = Cache.new
|
48
|
+
relations.each do |name|
|
49
|
+
define_readers_for_relation(cache, name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# @api private
|
54
|
+
def define_readers_for_relation(cache, name)
|
55
|
+
define_method(name) do |**kwargs|
|
56
|
+
relation_reader(cache, name, **kwargs)
|
57
|
+
end
|
58
|
+
end
|
28
59
|
end
|
29
60
|
|
30
61
|
# @api private
|
31
|
-
def
|
32
|
-
super
|
33
|
-
klass.include(InstanceMethods)
|
34
|
-
end
|
62
|
+
def initialize(relations:, cache:, root: Undefined)
|
63
|
+
super()
|
35
64
|
|
36
|
-
|
65
|
+
add_readers(relations, cache, root)
|
66
|
+
end
|
37
67
|
|
38
68
|
# @api private
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
69
|
+
def add_readers(relations, cache, root)
|
70
|
+
include cache.fetch_or_store(:relation_readers) {
|
71
|
+
Readers.new(relations)
|
72
|
+
}
|
73
|
+
|
74
|
+
unless Undefined.equal?(root)
|
75
|
+
define_method(:root) { |**kwargs| public_send(root, **kwargs) }
|
44
76
|
end
|
45
77
|
end
|
46
78
|
end
|
data/lib/rom/repository/root.rb
CHANGED
@@ -43,9 +43,10 @@ module ROM
|
|
43
43
|
# @return [Symbol]
|
44
44
|
defines :root
|
45
45
|
|
46
|
-
#
|
47
|
-
|
48
|
-
|
46
|
+
# @api public
|
47
|
+
def self.new(*args, **kwargs)
|
48
|
+
super(*args, **kwargs, root: root)
|
49
|
+
end
|
49
50
|
|
50
51
|
# Sets descendant root relation
|
51
52
|
#
|
@@ -54,13 +55,6 @@ module ROM
|
|
54
55
|
super
|
55
56
|
klass.root(root)
|
56
57
|
end
|
57
|
-
|
58
|
-
# @see Repository#initialize
|
59
|
-
def initialize(*)
|
60
|
-
super
|
61
|
-
@root = set_relation(self.class.root)
|
62
|
-
end
|
63
|
-
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
data/lib/rom/repository.rb
CHANGED
@@ -80,8 +80,9 @@ module ROM
|
|
80
80
|
|
81
81
|
# @!method self.relation_reader
|
82
82
|
# Get or set relation reader module
|
83
|
-
# @return [
|
83
|
+
# @return [Module]
|
84
84
|
defines :relation_reader
|
85
|
+
relation_reader RelationReader
|
85
86
|
|
86
87
|
struct_namespace ROM::Struct
|
87
88
|
|
@@ -104,11 +105,10 @@ module ROM
|
|
104
105
|
# Initializes a new repository object
|
105
106
|
#
|
106
107
|
# @api private
|
107
|
-
def initialize(
|
108
|
+
def initialize(*, **)
|
108
109
|
super
|
109
110
|
@relations = {}
|
110
111
|
end
|
111
|
-
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
112
112
|
|
113
113
|
# Open a database transaction
|
114
114
|
#
|
@@ -143,8 +143,8 @@ module ROM
|
|
143
143
|
# # => #<ROM::Struct::User id=1 name="Jane">
|
144
144
|
#
|
145
145
|
# @api public
|
146
|
-
def transaction(
|
147
|
-
container.gateways[:default].transaction(
|
146
|
+
def transaction(...)
|
147
|
+
container.gateways[:default].transaction(...)
|
148
148
|
end
|
149
149
|
|
150
150
|
# Return a string representation of a repository object
|
metadata
CHANGED
@@ -1,35 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-repository
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: dry-initializer
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 3.0.1
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '3.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0.1
|
33
12
|
- !ruby/object:Gem::Dependency
|
34
13
|
name: dry-core
|
35
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,53 +24,33 @@ dependencies:
|
|
45
24
|
- !ruby/object:Gem::Version
|
46
25
|
version: '1.0'
|
47
26
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
27
|
+
name: dry-initializer
|
49
28
|
requirement: !ruby/object:Gem::Requirement
|
50
29
|
requirements:
|
51
30
|
- - "~>"
|
52
31
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 5.3.0
|
32
|
+
version: '3.2'
|
57
33
|
type: :runtime
|
58
34
|
prerelease: false
|
59
35
|
version_requirements: !ruby/object:Gem::Requirement
|
60
36
|
requirements:
|
61
37
|
- - "~>"
|
62
38
|
- !ruby/object:Gem::Version
|
63
|
-
version: '
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 5.3.0
|
39
|
+
version: '3.2'
|
67
40
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '11.2'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '11.2'
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rspec
|
41
|
+
name: rom-core
|
83
42
|
requirement: !ruby/object:Gem::Requirement
|
84
43
|
requirements:
|
85
44
|
- - "~>"
|
86
45
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
88
|
-
type: :
|
46
|
+
version: '5.4'
|
47
|
+
type: :runtime
|
89
48
|
prerelease: false
|
90
49
|
version_requirements: !ruby/object:Gem::Requirement
|
91
50
|
requirements:
|
92
51
|
- - "~>"
|
93
52
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
53
|
+
version: '5.4'
|
95
54
|
description: Repository abstraction for rom-rb
|
96
55
|
email: piotr.solnica+oss@gmail.com
|
97
56
|
executables: []
|
@@ -116,7 +75,7 @@ metadata:
|
|
116
75
|
documentation_uri: https://api.rom-rb.org/rom/
|
117
76
|
mailing_list_uri: https://discourse.rom-rb.org/
|
118
77
|
bug_tracker_uri: https://github.com/rom-rb/rom/issues
|
119
|
-
|
78
|
+
rubygems_mfa_required: 'true'
|
120
79
|
rdoc_options: []
|
121
80
|
require_paths:
|
122
81
|
- lib
|
@@ -131,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
90
|
- !ruby/object:Gem::Version
|
132
91
|
version: '0'
|
133
92
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
135
|
-
signing_key:
|
93
|
+
rubygems_version: 3.6.2
|
136
94
|
specification_version: 4
|
137
95
|
summary: Repository abstraction for rom-rb
|
138
96
|
test_files: []
|