async-service 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c5d89c7f841e6cbe16bad8337324981ef85f1da92d2a8b8acada2c12a51c91c
4
- data.tar.gz: 0fe963d6d034ce7b2c0644405fd2044cbd6645c61514d3be3698fdf0a2a52f7c
3
+ metadata.gz: 9712448ebd0e8279fcc9820181ba9f72eb4799fc9735118fbbaea548b1650ff4
4
+ data.tar.gz: c71431b601e6fc9d5f1635a47a865b028fc7bb6c6c893c4496fe46dd73c485bb
5
5
  SHA512:
6
- metadata.gz: 86087e42a857958582c02812a59391378f6ba8a62beb49641a67d90db744c6007299926b5b0d41db0a13fc1cbf8fe498593a5e1c45e65f57fcd6e03ecdd4f4b6
7
- data.tar.gz: 17b9d71be9c88bcbbb52dfb0f15a75bf914062c757cfd4b4fbef058d83c99ea664495c58de3d7f3c6758438bb9d52fcf027124bbe8d6ad3e187c121e790e8827
6
+ metadata.gz: cfb98e0d17511c3b917bfd98ed278f79f643e94cfaf2f93002076974ca2ffa0621fa8dde402d845eb5c49ba63f6d96ce23e9f864dccd233c1e17c68c610a1c5b
7
+ data.tar.gz: bcc17aa016c6b972f4155071ec819f2b54dae4c925c5bcad6a8132651dd6cc6a8f9bcbecc950a148190be7011ed80f12d2a0596958db60e78720a1f116fccaf4
checksums.yaml.gz.sig CHANGED
Binary file
@@ -5,6 +5,7 @@
5
5
 
6
6
  require_relative 'loader'
7
7
  require_relative 'generic'
8
+ require_relative 'controller'
8
9
 
9
10
  module Async
10
11
  module Service
@@ -33,14 +34,20 @@ module Async
33
34
  @environments.empty?
34
35
  end
35
36
 
36
- def services
37
- return to_enum(:services) unless block_given?
37
+ def services(implementing: nil)
38
+ return to_enum(:services, implementing: implementing) unless block_given?
38
39
 
39
40
  @environments.each do |environment|
41
+ next if implementing and environment.implements?(implementing)
42
+
40
43
  yield Generic.wrap(environment)
41
44
  end
42
45
  end
43
46
 
47
+ def controller(**options)
48
+ Controller.new(self.services(**options).to_a)
49
+ end
50
+
44
51
  # Add the environment to the configuration.
45
52
  def add(environment)
46
53
  @environments << environment
@@ -38,6 +38,10 @@ module Async
38
38
  @services = services
39
39
  end
40
40
 
41
+ # All the services associated with this controller.
42
+ # @attribute [Array(Async::Service::Generic)]
43
+ attr :services
44
+
41
45
  # Start all named services.
42
46
  def start
43
47
  @services.each do |service|
@@ -59,6 +59,12 @@ module Async
59
59
  @parent = parent
60
60
  end
61
61
 
62
+ # @attribute [Module] The facet module.
63
+ attr :facet
64
+
65
+ # @attribute [Environment | Nil] The parent environment, if any.
66
+ attr :parent
67
+
62
68
  def included(target)
63
69
  @parent&.included(target)
64
70
  target.include(@facet)
@@ -68,6 +74,10 @@ module Async
68
74
  return self.class.new(Builder.for(...), self)
69
75
  end
70
76
 
77
+ def implements?(interface)
78
+ @facet <= interface
79
+ end
80
+
71
81
  # An evaluator is lazy read-only view of an environment. It memoizes all method calls.
72
82
  class Evaluator
73
83
  def self.wrap(environment)
@@ -78,16 +88,24 @@ module Async
78
88
 
79
89
  evaluator.include(facet)
80
90
 
91
+ keys = []
92
+
81
93
  # Memoize all instance methods:
82
94
  facet.instance_methods.each do |name|
83
- evaluator.define_method(name) do
84
- @cache[name] ||= super()
95
+ instance_method = facet.instance_method(name)
96
+
97
+ # Only memoize methods with no arguments:
98
+ if instance_method.arity == 0
99
+ keys << name
100
+
101
+ evaluator.define_method(name) do
102
+ @cache[name] ||= super()
103
+ end
85
104
  end
86
105
  end
87
106
 
88
- evaluator.define_method(:keys) do
89
- facet.instance_methods
90
- end
107
+ # This lists all zero-argument methods:
108
+ evaluator.define_method(:keys) {keys}
91
109
 
92
110
  return evaluator.new
93
111
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Service
8
- VERSION = "0.6.1"
8
+ VERSION = "0.8.0"
9
9
  end
10
10
  end
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.6.1
4
+ version: 0.8.0
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-03-17 00:00:00.000000000 Z
40
+ date: 2024-03-22 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async
metadata.gz.sig CHANGED
Binary file