igniter-embed 0.5.2
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 +7 -0
- data/README.md +360 -0
- data/lib/igniter/embed/config.rb +155 -0
- data/lib/igniter/embed/container.rb +165 -0
- data/lib/igniter/embed/contract_handle.rb +23 -0
- data/lib/igniter/embed/contract_naming.rb +38 -0
- data/lib/igniter/embed/contractable/acceptance.rb +52 -0
- data/lib/igniter/embed/contractable/adapters.rb +33 -0
- data/lib/igniter/embed/contractable/config.rb +234 -0
- data/lib/igniter/embed/contractable/runner.rb +393 -0
- data/lib/igniter/embed/contractable/sugar_builder.rb +145 -0
- data/lib/igniter/embed/contractable.rb +29 -0
- data/lib/igniter/embed/contracts_builder.rb +54 -0
- data/lib/igniter/embed/errors.rb +14 -0
- data/lib/igniter/embed/execution_envelope.rb +50 -0
- data/lib/igniter/embed/host_builder.rb +39 -0
- data/lib/igniter/embed/rails.rb +21 -0
- data/lib/igniter/embed/registry.rb +78 -0
- data/lib/igniter/embed/sugar_expansion.rb +152 -0
- data/lib/igniter/embed.rb +38 -0
- data/lib/igniter-embed.rb +3 -0
- metadata +89 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Igniter
|
|
4
|
+
module Embed
|
|
5
|
+
class HostBuilder
|
|
6
|
+
def initialize(config:)
|
|
7
|
+
@config = config
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def owner(value)
|
|
11
|
+
config.owner(value)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def path(value)
|
|
15
|
+
config.path(value)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def root(value)
|
|
19
|
+
config.root(value)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def cache(value)
|
|
23
|
+
config.cache = value
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def contract(definition, as: nil)
|
|
27
|
+
config.contract(definition, as: as)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def contracts(&block)
|
|
31
|
+
config.contracts(&block)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
attr_reader :config
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../embed"
|
|
4
|
+
|
|
5
|
+
module Igniter
|
|
6
|
+
module Embed
|
|
7
|
+
module Rails
|
|
8
|
+
class << self
|
|
9
|
+
def install(container, reloader: nil, cache: nil)
|
|
10
|
+
container.config.cache = cache unless cache.nil?
|
|
11
|
+
return container unless reloader
|
|
12
|
+
|
|
13
|
+
raise RailsIntegrationError, "Rails reloader must respond to #to_prepare" unless reloader.respond_to?(:to_prepare)
|
|
14
|
+
|
|
15
|
+
reloader.to_prepare { container.reload! }
|
|
16
|
+
container
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Igniter
|
|
4
|
+
module Embed
|
|
5
|
+
class Registry
|
|
6
|
+
Registration = Struct.new(:name, :definition, :kind, keyword_init: true) do
|
|
7
|
+
def block?
|
|
8
|
+
kind == :block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def class?
|
|
12
|
+
kind == :class
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_h
|
|
16
|
+
{
|
|
17
|
+
name: name,
|
|
18
|
+
kind: kind,
|
|
19
|
+
definition: definition_name
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def definition_name
|
|
26
|
+
return definition.name if definition.respond_to?(:name) && definition.name
|
|
27
|
+
|
|
28
|
+
definition.inspect
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def initialize
|
|
33
|
+
@contracts = {}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def register(name, definition)
|
|
37
|
+
key = normalize_name(name)
|
|
38
|
+
raise DuplicateContractError, "contract #{key} is already registered" if contracts.key?(key)
|
|
39
|
+
|
|
40
|
+
contracts[key] = Registration.new(name: key, definition: definition, kind: kind_for(definition))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def fetch(name)
|
|
44
|
+
key = normalize_name(name)
|
|
45
|
+
contracts.fetch(key)
|
|
46
|
+
rescue KeyError
|
|
47
|
+
raise UnknownContractError, "unknown contract #{key}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def key?(name)
|
|
51
|
+
contracts.key?(normalize_name(name))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def names
|
|
55
|
+
contracts.keys
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_h
|
|
59
|
+
contracts.transform_values(&:to_h)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
attr_reader :contracts
|
|
65
|
+
|
|
66
|
+
def normalize_name(name)
|
|
67
|
+
name.to_sym
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def kind_for(definition)
|
|
71
|
+
return :class if definition.is_a?(Class) && definition < Igniter::Contract
|
|
72
|
+
return :block if definition.respond_to?(:call)
|
|
73
|
+
|
|
74
|
+
raise ArgumentError, "contract definition must be a block or Class < Igniter::Contract"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Igniter
|
|
4
|
+
module Embed
|
|
5
|
+
class SugarExpansion
|
|
6
|
+
def initialize(config:)
|
|
7
|
+
@config = config
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_h
|
|
11
|
+
{
|
|
12
|
+
host: config.name,
|
|
13
|
+
owner: owner_name,
|
|
14
|
+
root: config.root,
|
|
15
|
+
cache: config.cache?,
|
|
16
|
+
contracts: contracts,
|
|
17
|
+
contractables: contractables,
|
|
18
|
+
capabilities: [],
|
|
19
|
+
events: [],
|
|
20
|
+
clean_config: clean_config
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
attr_reader :config
|
|
27
|
+
|
|
28
|
+
def owner_name
|
|
29
|
+
owner = config.owner
|
|
30
|
+
return nil unless owner
|
|
31
|
+
return owner.name if owner.respond_to?(:name) && owner.name
|
|
32
|
+
|
|
33
|
+
owner.inspect
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def contracts
|
|
37
|
+
config.contract_registrations.map do |registration|
|
|
38
|
+
{
|
|
39
|
+
name: registration_name(registration),
|
|
40
|
+
class: registration_class(registration),
|
|
41
|
+
kind: registration_kind(registration)
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def clean_config
|
|
47
|
+
{
|
|
48
|
+
name: config.name,
|
|
49
|
+
owner: owner_name,
|
|
50
|
+
root: config.root,
|
|
51
|
+
cache: config.cache?,
|
|
52
|
+
contracts: contracts
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def contractables
|
|
57
|
+
config.contractable_configs.map do |contractable_config|
|
|
58
|
+
{
|
|
59
|
+
name: contractable_config.name,
|
|
60
|
+
role: contractable_config.role,
|
|
61
|
+
stage: contractable_config.stage,
|
|
62
|
+
primary: callable_name(contractable_config.primary),
|
|
63
|
+
candidate: callable_name(contractable_config.candidate),
|
|
64
|
+
async: contractable_config.async,
|
|
65
|
+
sample: contractable_config.sample,
|
|
66
|
+
metadata: contractable_config.metadata,
|
|
67
|
+
adapters: adapters(contractable_config),
|
|
68
|
+
capabilities: capabilities(contractable_config),
|
|
69
|
+
events: events(contractable_config),
|
|
70
|
+
runner: runner(contractable_config)
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def registration_name(registration)
|
|
76
|
+
return registration.name.to_sym if registration.name
|
|
77
|
+
return ContractNaming.infer_contract_name(registration.definition) if ContractNaming.contract_class?(registration.definition)
|
|
78
|
+
|
|
79
|
+
nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def registration_class(registration)
|
|
83
|
+
definition = registration.definition
|
|
84
|
+
return definition.name if ContractNaming.contract_class?(definition) && definition.name
|
|
85
|
+
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def registration_kind(registration)
|
|
90
|
+
ContractNaming.contract_class?(registration.definition) ? :class : :block
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def callable_name(callable)
|
|
94
|
+
return nil unless callable
|
|
95
|
+
return callable.name if callable.respond_to?(:name) && callable.name
|
|
96
|
+
|
|
97
|
+
callable.inspect
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def adapters(contractable_config)
|
|
101
|
+
{
|
|
102
|
+
normalizer: normalizer_adapter(contractable_config),
|
|
103
|
+
redaction: callable_name(contractable_config.redact_inputs),
|
|
104
|
+
acceptance: acceptance_adapter(contractable_config),
|
|
105
|
+
store: callable_name(contractable_config.store)
|
|
106
|
+
}.compact
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def normalizer_adapter(contractable_config)
|
|
110
|
+
primary = callable_name(contractable_config.normalize_primary)
|
|
111
|
+
candidate = callable_name(contractable_config.normalize_candidate)
|
|
112
|
+
return primary if primary == candidate
|
|
113
|
+
|
|
114
|
+
{ primary: primary, candidate: candidate }.compact
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def acceptance_adapter(contractable_config)
|
|
118
|
+
{
|
|
119
|
+
policy: contractable_config.accept,
|
|
120
|
+
options: contractable_config.acceptance_options
|
|
121
|
+
}
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def events(contractable_config)
|
|
125
|
+
contractable_config.event_handlers.map do |event_handler|
|
|
126
|
+
{
|
|
127
|
+
event: event_handler.event,
|
|
128
|
+
source: event_handler.source,
|
|
129
|
+
handler: callable_name(event_handler.handler)
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def capabilities(contractable_config)
|
|
135
|
+
contractable_config.capability_attachments.map do |attachment|
|
|
136
|
+
{
|
|
137
|
+
name: attachment.name,
|
|
138
|
+
kind: attachment.kind,
|
|
139
|
+
target: callable_name(attachment.target)
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def runner(contractable_config)
|
|
145
|
+
{
|
|
146
|
+
accessor: "contractable(:#{contractable_config.name})",
|
|
147
|
+
materializable: true
|
|
148
|
+
}
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "igniter/contracts"
|
|
4
|
+
require "igniter/extensions/contracts"
|
|
5
|
+
|
|
6
|
+
require_relative "embed/errors"
|
|
7
|
+
require_relative "embed/contract_naming"
|
|
8
|
+
require_relative "embed/config"
|
|
9
|
+
require_relative "embed/contracts_builder"
|
|
10
|
+
require_relative "embed/sugar_expansion"
|
|
11
|
+
require_relative "embed/host_builder"
|
|
12
|
+
require_relative "embed/registry"
|
|
13
|
+
require_relative "embed/execution_envelope"
|
|
14
|
+
require_relative "embed/contract_handle"
|
|
15
|
+
require_relative "embed/container"
|
|
16
|
+
require_relative "embed/contractable"
|
|
17
|
+
|
|
18
|
+
module Igniter
|
|
19
|
+
module Embed
|
|
20
|
+
class << self
|
|
21
|
+
def configure(name, &block)
|
|
22
|
+
config = Config.new(name: name)
|
|
23
|
+
block&.call(config)
|
|
24
|
+
Container.new(config: config)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def host(name, &block)
|
|
28
|
+
config = Config.new(name: name)
|
|
29
|
+
HostBuilder.new(config: config).instance_eval(&block) if block
|
|
30
|
+
Container.new(config: config)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def contractable(name, &block)
|
|
34
|
+
Contractable.build(name, &block)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: igniter-embed
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alexander
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: igniter-contracts
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - '='
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.5.2
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - '='
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.5.2
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: igniter-extensions
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - '='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.5.2
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - '='
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.5.2
|
|
40
|
+
description: Embedded host container, registry, cache, and execution envelope for
|
|
41
|
+
Igniter contracts.
|
|
42
|
+
email:
|
|
43
|
+
- alexander.s.fokin@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- README.md
|
|
49
|
+
- lib/igniter-embed.rb
|
|
50
|
+
- lib/igniter/embed.rb
|
|
51
|
+
- lib/igniter/embed/config.rb
|
|
52
|
+
- lib/igniter/embed/container.rb
|
|
53
|
+
- lib/igniter/embed/contract_handle.rb
|
|
54
|
+
- lib/igniter/embed/contract_naming.rb
|
|
55
|
+
- lib/igniter/embed/contractable.rb
|
|
56
|
+
- lib/igniter/embed/contractable/acceptance.rb
|
|
57
|
+
- lib/igniter/embed/contractable/adapters.rb
|
|
58
|
+
- lib/igniter/embed/contractable/config.rb
|
|
59
|
+
- lib/igniter/embed/contractable/runner.rb
|
|
60
|
+
- lib/igniter/embed/contractable/sugar_builder.rb
|
|
61
|
+
- lib/igniter/embed/contracts_builder.rb
|
|
62
|
+
- lib/igniter/embed/errors.rb
|
|
63
|
+
- lib/igniter/embed/execution_envelope.rb
|
|
64
|
+
- lib/igniter/embed/host_builder.rb
|
|
65
|
+
- lib/igniter/embed/rails.rb
|
|
66
|
+
- lib/igniter/embed/registry.rb
|
|
67
|
+
- lib/igniter/embed/sugar_expansion.rb
|
|
68
|
+
homepage: https://github.com/alexander-s-f/igniter
|
|
69
|
+
licenses:
|
|
70
|
+
- MIT
|
|
71
|
+
metadata: {}
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: 3.1.0
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 4.0.10
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Host-local embedded contract containers for Igniter
|
|
89
|
+
test_files: []
|