realm-core 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/realm.rb +9 -0
- data/lib/realm/action_handler.rb +11 -13
- data/lib/realm/contract.rb +42 -0
- data/lib/realm/struct.rb +48 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e6f3990f8dc36366899e3a8bbf1835bf6cf0bb880bcf13333f394b40d1075e3
|
4
|
+
data.tar.gz: a03e2bb0fa656cfaada1364db1d8af4c222cbaff8cec5ffd0223629b40e11bc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 627b95689b8a4d51fb15a8665dd65be88974380c00a168f1121ae5248738140eadd82f3735ccaa0391fb33274952a9e1fe83819813b7312921b9adeb85956816
|
7
|
+
data.tar.gz: ed1a34e594acb1e7f3ef3d644aecad58af6b9fdc1b436fb3ba793cdbdc131affdecf26e832b9d2997ab45501dba91bda950735e3e85bbd518cf5e7eaaea2ce7e
|
data/lib/realm.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'active_support/all'
|
4
|
+
require 'dry/core/constants'
|
4
5
|
|
5
6
|
module Realm
|
6
7
|
class << self
|
@@ -16,5 +17,13 @@ module Realm
|
|
16
17
|
root_module.define_singleton_method(:realm) { builder.runtime }
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
# port the construction method from Dry::Struct as it's not inherited
|
22
|
+
def Struct(attributes = Dry::Core::Constants::EMPTY_HASH, &block) # rubocop:disable Naming/MethodName
|
23
|
+
Class.new(Struct) do
|
24
|
+
attributes.each { |a, type| attribute a, type }
|
25
|
+
module_eval(&block) if block
|
26
|
+
end
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|
data/lib/realm/action_handler.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'dry-validation'
|
4
|
-
require 'active_support/core_ext/module/delegation'
|
5
|
-
require 'realm/error'
|
6
|
-
require 'realm/mixins/context_injection'
|
7
|
-
require 'realm/mixins/repository_helper'
|
8
|
-
require 'realm/mixins/aggregate_member'
|
9
|
-
require_relative 'action_handler/result'
|
10
4
|
|
11
5
|
module Realm
|
12
6
|
class ActionHandler
|
@@ -28,21 +22,25 @@ module Realm
|
|
28
22
|
end
|
29
23
|
|
30
24
|
def contract(&block)
|
31
|
-
@method_contract = Class.new(
|
25
|
+
@method_contract = Class.new(Realm::Contract, &block).new
|
32
26
|
end
|
33
27
|
|
34
|
-
def contract_schema(
|
35
|
-
contract { schema(
|
28
|
+
def contract_schema(...)
|
29
|
+
contract { schema(...) }
|
36
30
|
end
|
37
31
|
|
38
|
-
def contract_params(
|
39
|
-
contract { params(
|
32
|
+
def contract_params(...)
|
33
|
+
contract { params(...) }
|
40
34
|
end
|
41
35
|
|
42
|
-
def contract_json(
|
43
|
-
contract { json(
|
36
|
+
def contract_json(...)
|
37
|
+
contract { json(...) }
|
44
38
|
end
|
45
39
|
|
40
|
+
alias schema_contract contract_schema
|
41
|
+
alias params_contract contract_params
|
42
|
+
alias json_contract contract_json
|
43
|
+
|
46
44
|
def method_added(method_name)
|
47
45
|
super
|
48
46
|
return unless defined?(@method_contract)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-validation'
|
4
|
+
|
5
|
+
module Realm
|
6
|
+
class Contract < Dry::Validation::Contract
|
7
|
+
class NotConvertibleToSchema < Realm::Error
|
8
|
+
def initialize(thing)
|
9
|
+
super("Not convertible to schema: #{thing}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def schema(*external_schemas, **attributes, &block)
|
15
|
+
super(*sanitize_schemas(external_schemas, attributes), &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def params(*external_schemas, **attributes, &block)
|
19
|
+
super(*sanitize_schemas(external_schemas, attributes), &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def json(*external_schemas, **attributes, &block)
|
23
|
+
super(*sanitize_schemas(external_schemas, attributes), &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def sanitize_schemas(things, attributes, type = :schema)
|
29
|
+
things << Realm.Struct(attributes) if attributes.present?
|
30
|
+
things.map { |thing| convert_to_schema(thing, type) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def convert_to_schema(thing, type)
|
34
|
+
return thing if thing.is_a? Dry::Schema::Processor # already a schema
|
35
|
+
|
36
|
+
raise NotConvertibleToSchema, thing unless thing.respond_to?(:to_dry_schema)
|
37
|
+
|
38
|
+
thing.to_dry_schema(type: type)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/realm/struct.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-struct'
|
4
|
+
require 'dry-schema'
|
5
|
+
|
6
|
+
module Realm
|
7
|
+
class Struct < Dry::Struct
|
8
|
+
class << self
|
9
|
+
def to_dry_schema(type: :schema) # rubocop:disable Metrics/AbcSize
|
10
|
+
keys = schema.type.keys
|
11
|
+
|
12
|
+
Dry::Schema.send(schema_type_to_method(type)) do
|
13
|
+
keys.each do |key|
|
14
|
+
param = key.required? ? required(key.name) : optional(key.name)
|
15
|
+
|
16
|
+
if key.type.constructor_type == Dry::Types::Array::Constructor # array type
|
17
|
+
member = key.type.member
|
18
|
+
param.array(member.respond_to?(:to_dry_schema) ? member.to_dry_schema(type: type) : member)
|
19
|
+
elsif key.respond_to?(:to_dry_schema) # realm struct
|
20
|
+
param.hash(key.to_dry_schema(type: type))
|
21
|
+
else
|
22
|
+
param.send(key.required? ? :filled : :maybe, key.type)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def merge(attributes)
|
29
|
+
clone.attributes(attributes)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def schema_type_to_method(type)
|
35
|
+
case type
|
36
|
+
when :schema
|
37
|
+
:define
|
38
|
+
when :params
|
39
|
+
:Params
|
40
|
+
when :json
|
41
|
+
:JSON
|
42
|
+
else
|
43
|
+
raise "Not supported schema type #{type}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realm-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- developers@reevoo.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- lib/realm/config.rb
|
180
180
|
- lib/realm/container.rb
|
181
181
|
- lib/realm/context.rb
|
182
|
+
- lib/realm/contract.rb
|
182
183
|
- lib/realm/dependency.rb
|
183
184
|
- lib/realm/dispatcher.rb
|
184
185
|
- lib/realm/domain_resolver.rb
|
@@ -204,6 +205,7 @@ files:
|
|
204
205
|
- lib/realm/query_handler.rb
|
205
206
|
- lib/realm/runtime.rb
|
206
207
|
- lib/realm/runtime/session.rb
|
208
|
+
- lib/realm/struct.rb
|
207
209
|
- lib/realm/types.rb
|
208
210
|
homepage:
|
209
211
|
licenses:
|