async-service 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/service/environment.rb +75 -72
- data/lib/async/service/loader.rb +1 -1
- data/lib/async/service/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 383a3a329442a291c3ec373e55626e1a10ab01e237aa545787f7282c8bace859
|
4
|
+
data.tar.gz: 0b3436a1ccf535c15fcd90b59b77dbc3e2638170496a2c7d8298d76134edb3a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f419c921dec91bd81a3b0a51e08471017fd3d8a31fb3fcfdf0abb0c53eb044b131f190be5a93f33b37d0a2eee3c4935ce55e3ce67bc3217db01b818abaa5fe24
|
7
|
+
data.tar.gz: 84decffdf10d7e0dc269f812e83dc5a780615a6d90ff51237743f1ffa48fd96e7b436516ecc4b1c14ea7ec8b0b379a2e8c613ef3affa0da3bf1b3f4f3103754c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -7,120 +7,123 @@ module Async
|
|
7
7
|
module Service
|
8
8
|
class Environment
|
9
9
|
class Builder < BasicObject
|
10
|
-
def self.
|
11
|
-
|
10
|
+
def self.wrap(hash, facet = ::Module.new)
|
11
|
+
hash.each do |key, value|
|
12
|
+
if value.is_a?(::Proc)
|
13
|
+
facet.define_method(key, &value)
|
14
|
+
else
|
15
|
+
facet.define_method(key){value}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
return facet
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.for(facet = ::Module.new, &block)
|
23
|
+
builder = self.new(facet)
|
12
24
|
|
13
|
-
builder.instance_exec(&block) if
|
25
|
+
builder.instance_exec(&block) if block_given?
|
14
26
|
|
15
|
-
return
|
27
|
+
return facet
|
16
28
|
end
|
17
29
|
|
18
|
-
def initialize(
|
19
|
-
@
|
30
|
+
def initialize(facet = ::Module.new)
|
31
|
+
@facet = facet
|
20
32
|
end
|
21
33
|
|
22
34
|
def include(target)
|
23
|
-
target.
|
24
|
-
@
|
35
|
+
if target.class == ::Module
|
36
|
+
@facet.include(target)
|
37
|
+
elsif target.respond_to?(:included)
|
38
|
+
target.included(@facet)
|
39
|
+
else
|
40
|
+
::Kernel.raise ::ArgumentError, "Cannot include #{target.inspect} into #{@facet.inspect}!"
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
28
44
|
def method_missing(name, argument = nil, &block)
|
29
|
-
previous = @cache[name]
|
30
|
-
|
31
45
|
if block
|
32
|
-
|
33
|
-
@cache[name] = block
|
34
|
-
else
|
35
|
-
# Bind the |previous| argument to the block:
|
36
|
-
@cache[name] = ::Kernel.lambda{self.instance_exec(previous, &block)}
|
37
|
-
end
|
38
|
-
elsif previous.is_a?(::Array)
|
39
|
-
@cache[name] = previous + argument
|
40
|
-
elsif previous.is_a?(::Hash)
|
41
|
-
@cache[name] = previous.merge(argument)
|
46
|
+
@facet.define_method(name, &block)
|
42
47
|
else
|
43
|
-
@
|
48
|
+
@facet.define_method(name){argument}
|
44
49
|
end
|
45
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.build(**values, &block)
|
54
|
+
if values.any?
|
55
|
+
environment = Environment.new(Builder.wrap(values))
|
56
|
+
end
|
46
57
|
|
47
|
-
|
48
|
-
|
58
|
+
if block_given?
|
59
|
+
environment = Environment.new(Builder.for(&block), environment)
|
49
60
|
end
|
61
|
+
|
62
|
+
return environment
|
50
63
|
end
|
51
64
|
|
52
|
-
def initialize(
|
53
|
-
@
|
54
|
-
@
|
65
|
+
def initialize(facet = ::Module.new, parent = nil)
|
66
|
+
@facet = facet
|
67
|
+
@parent = parent
|
55
68
|
end
|
56
69
|
|
57
|
-
def
|
58
|
-
|
70
|
+
def included(target)
|
71
|
+
@parent&.included(target)
|
72
|
+
target.include(@facet)
|
59
73
|
end
|
60
74
|
|
61
|
-
# An evaluator is lazy read-only view of an environment. It
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
value.collect{|item| __evaluate__(item)}
|
77
|
-
when ::Hash
|
78
|
-
value.transform_values{|item| __evaluate__(item)}
|
79
|
-
# when ::Symbol
|
80
|
-
# self[value]
|
81
|
-
when ::Proc
|
82
|
-
__evaluate__(instance_exec(&value))
|
83
|
-
else
|
84
|
-
value
|
75
|
+
# An evaluator is lazy read-only view of an environment. It memoizes all method calls.
|
76
|
+
class Evaluator
|
77
|
+
def self.wrap(environment)
|
78
|
+
evaluator = ::Class.new(self)
|
79
|
+
|
80
|
+
facet = ::Module.new
|
81
|
+
environment.included(facet)
|
82
|
+
|
83
|
+
evaluator.include(facet)
|
84
|
+
|
85
|
+
# Memoize all instance methods:
|
86
|
+
facet.instance_methods.each do |name|
|
87
|
+
evaluator.define_method(name) do
|
88
|
+
@cache[name] ||= super()
|
89
|
+
end
|
85
90
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@cache.fetch(key) do
|
90
|
-
@cache[key] = __evaluate__(@source[key])
|
91
|
+
|
92
|
+
evaluator.define_method(:keys) do
|
93
|
+
facet.instance_methods
|
91
94
|
end
|
95
|
+
|
96
|
+
return evaluator.new
|
92
97
|
end
|
93
98
|
|
94
|
-
def
|
95
|
-
@
|
99
|
+
def initialize
|
100
|
+
@cache = {}
|
96
101
|
end
|
97
102
|
|
98
|
-
def
|
99
|
-
|
100
|
-
self[name]
|
101
|
-
else
|
102
|
-
super
|
103
|
-
end
|
103
|
+
def inspect
|
104
|
+
"#<#{Evaluator} #{self.keys}>"
|
104
105
|
end
|
105
106
|
|
106
107
|
def to_h
|
107
108
|
# Ensure all keys are evaluated:
|
108
|
-
|
109
|
+
self.keys.each do |name|
|
110
|
+
self.__send__(name)
|
111
|
+
end
|
109
112
|
|
110
113
|
return @cache
|
111
114
|
end
|
112
115
|
|
116
|
+
def [](key)
|
117
|
+
self.__send__(key)
|
118
|
+
end
|
119
|
+
|
113
120
|
def key?(key)
|
114
|
-
|
121
|
+
self.keys.include?(key)
|
115
122
|
end
|
116
123
|
end
|
117
124
|
|
118
125
|
def evaluator
|
119
|
-
Evaluator.
|
120
|
-
end
|
121
|
-
|
122
|
-
def each(&block)
|
123
|
-
builder.to_h.each(&block)
|
126
|
+
return Evaluator.wrap(self)
|
124
127
|
end
|
125
128
|
|
126
129
|
def to_h
|
data/lib/async/service/loader.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2024-
|
40
|
+
date: 2024-03-10 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: async
|
metadata.gz.sig
CHANGED
Binary file
|