Class: Foobara::CommandRegistry
- Inherits:
-
Object
- Object
- Foobara::CommandRegistry
show all
- Includes:
- TruncatedInspect
- Defined in:
- foobara-0.5.8/projects/command_connectors/src/command_registry/allowed_rule.rb,
foobara-0.5.8/projects/command_connectors/src/command_registry.rb,
foobara-0.5.8/projects/command_connectors/src/command_registry/exposed_domain.rb,
foobara-0.5.8/projects/command_connectors/src/command_registry/exposed_command.rb,
foobara-0.5.8/projects/command_connectors/src/command_registry/exposed_organization.rb
Overview
TODO: move to foobara monorepo if this is generic…
Defined Under Namespace
Modules: ExposedDomain, ExposedOrganization
Classes: AllowedRule, ExposedCommand
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
#inspect, truncating
Constructor Details
#initialize(authenticator: nil, allow: nil) ⇒ CommandRegistry
Should we support different authenticators for different commands? Might be a smell of two domains co-habitating in one? Or maybe one is just passing another through and we should support that?
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'projects/command_connectors/src/command_registry.rb', line 12
def initialize(authenticator: nil, allow: nil)
self.scoped_path = []
self.authenticator = authenticator
self.allow allow if allow
customized = [:command]
Namespace.global.foobara_categories.keys.reverse.each do |symbol|
next if customized.include?(symbol)
proc = Namespace.global.foobara_categories[symbol]
foobara_add_category(symbol, &proc)
end
foobara_add_category_for_instance_of(:command, ExposedCommand)
foobara_depends_on_namespaces << Namespace.global
end
|
Instance Attribute Details
#authenticator ⇒ Object
Returns the value of attribute authenticator.
7
8
9
|
# File 'projects/command_connectors/src/command_registry.rb', line 7
def authenticator
@authenticator
end
|
#default_allowed_rule ⇒ Object
Returns the value of attribute default_allowed_rule.
7
8
9
|
# File 'projects/command_connectors/src/command_registry.rb', line 7
def default_allowed_rule
@default_allowed_rule
end
|
Instance Method Details
#[](name) ⇒ Object
108
109
110
111
112
113
114
|
# File 'projects/command_connectors/src/command_registry.rb', line 108
def [](name)
if name.is_a?(Class)
name.full_command_name
end
foobara_lookup(name)
end
|
161
162
163
|
# File 'projects/command_connectors/src/command_registry.rb', line 161
def add_default_errors_transformer(transformer)
default_errors_transformers << transformer
end
|
145
146
147
|
# File 'projects/command_connectors/src/command_registry.rb', line 145
def add_default_inputs_transformer(transformer)
default_inputs_transformers << transformer
end
|
169
170
171
|
# File 'projects/command_connectors/src/command_registry.rb', line 169
def add_default_pre_commit_transformer(transformer)
default_pre_commit_transformers << transformer
end
|
153
154
155
|
# File 'projects/command_connectors/src/command_registry.rb', line 153
def add_default_result_transformer(transformer)
default_result_transformers << transformer
end
|
#add_default_serializer(serializer) ⇒ Object
177
178
179
|
# File 'projects/command_connectors/src/command_registry.rb', line 177
def add_default_serializer(serializer)
default_serializers << serializer
end
|
185
186
187
|
# File 'projects/command_connectors/src/command_registry.rb', line 185
def all_transformed_command_classes
foobara_all_command.map(&:transformed_command_class)
end
|
#allow(rules = (no_args = true)) ⇒ Object
197
198
199
200
201
202
203
204
205
|
# File 'projects/command_connectors/src/command_registry.rb', line 197
def allow(rules = (no_args = true))
@allow ||= {}
if no_args
@allow
else
@allow = @allow.merge(rules)
end
end
|
#allowed_rule ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
|
# File 'projects/command_connectors/src/command_registry.rb', line 120
def allowed_rule(*)
allowed_rule = to_allowed_rule(*)
unless allowed_rule.symbol
raise "Cannot register a rule without a symbol"
end
allowed_rule_registry[allowed_rule.symbol] = allowed_rule
end
|
#allowed_rule_registry ⇒ Object
116
117
118
|
# File 'projects/command_connectors/src/command_registry.rb', line 116
def allowed_rule_registry
@allowed_rule_registry ||= {}
end
|
#allowed_rules(hash) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'projects/command_connectors/src/command_registry.rb', line 132
def allowed_rules(hash)
hash.map do |symbol, ruleish|
allowed_rule = to_allowed_rule(ruleish)
allowed_rule.symbol = symbol
allowed_rule(allowed_rule)
end
end
|
#build_and_register_exposed_domain(domain_full_name) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'projects/command_connectors/src/command_registry.rb', line 41
def build_and_register_exposed_domain(domain_full_name)
domain_module = if domain_full_name.to_s == ""
GlobalDomain
else
Namespace.global.foobara_lookup_domain!(domain_full_name)
end
full_organization_name = domain_module.foobara_full_organization_name
exposed_organization = foobara_lookup_organization(
full_organization_name,
mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
) || build_and_register_exposed_organization(full_organization_name)
exposed_domain = Module.new
exposed_domain.foobara_namespace!
exposed_domain.foobara_domain!
exposed_domain.extend(ExposedDomain)
exposed_domain.unexposed_domain = domain_module
exposed_domain.foobara_depends_on domain_module
exposed_organization.foobara_register(exposed_domain)
domain_module.foobara_depends_on.each do |domain_name|
unless foobara_domain_registered?(domain_name)
build_and_register_exposed_domain(domain_name)
end
end
exposed_domain
end
|
#build_and_register_exposed_organization(full_organization_name) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'projects/command_connectors/src/command_registry.rb', line 90
def build_and_register_exposed_organization(full_organization_name)
org = if full_organization_name.to_s == ""
GlobalOrganization
else
Namespace.global.foobara_lookup_organization!(full_organization_name)
end
exposed_organization = Module.new
exposed_organization.foobara_namespace!
exposed_organization.foobara_organization!
exposed_organization.extend(ExposedOrganization)
exposed_organization.unexposed_organization = org
foobara_register(exposed_organization)
exposed_organization
end
|
#create_exposed_command_without_domain(command_class) ⇒ Object
TODO: eliminate this method
37
38
39
|
# File 'projects/command_connectors/src/command_registry.rb', line 37
def create_exposed_command_without_domain(command_class, **)
ExposedCommand.new(command_class, **apply_defaults(**))
end
|
157
158
159
|
# File 'projects/command_connectors/src/command_registry.rb', line 157
def default_errors_transformers
@default_errors_transformers ||= []
end
|
141
142
143
|
# File 'projects/command_connectors/src/command_registry.rb', line 141
def default_inputs_transformers
@default_inputs_transformers ||= []
end
|
165
166
167
|
# File 'projects/command_connectors/src/command_registry.rb', line 165
def default_pre_commit_transformers
@default_pre_commit_transformers ||= []
end
|
149
150
151
|
# File 'projects/command_connectors/src/command_registry.rb', line 149
def default_result_transformers
@default_result_transformers ||= []
end
|
#default_serializers ⇒ Object
173
174
175
|
# File 'projects/command_connectors/src/command_registry.rb', line 173
def default_serializers
@default_serializers ||= []
end
|
189
190
191
|
# File 'projects/command_connectors/src/command_registry.rb', line 189
def each_transformed_command_class(&)
foobara_all_command.map(&:transformed_command_class).each(&)
end
|
#global_domain ⇒ Object
77
78
79
80
|
# File 'projects/command_connectors/src/command_registry.rb', line 77
def global_domain
foobara_lookup_domain("", mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) ||
build_and_register_exposed_domain("")
end
|
#global_organization ⇒ Object
82
83
84
85
86
87
88
|
# File 'projects/command_connectors/src/command_registry.rb', line 82
def global_organization
foobara_lookup_organization("", mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE) ||
build_and_register_exposed_organization("")
end
|
#register(command_class) ⇒ Object
32
33
34
|
# File 'projects/command_connectors/src/command_registry.rb', line 32
def register(command_class, **)
create_exposed_command(command_class, **)
end
|
#size ⇒ Object
193
194
195
|
# File 'projects/command_connectors/src/command_registry.rb', line 193
def size
foobara_all_command.size
end
|
181
182
183
|
# File 'projects/command_connectors/src/command_registry.rb', line 181
def transformed_command_from_name(name)
foobara_lookup_command(name, mode: Namespace::LookupMode::RELAXED)&.transformed_command_class
end
|