No more async in list_for
Stephen Paul Weber
created 1 month ago
We have a loader, let's use it
Probably we want to load list of command as part of the sgx repo? But
maybe that's too heavy and we don't always need it?
Change summary
lib/command_list.rb | 16 +++++++---------
sgx_jmp.rb | 10 ++++------
2 files changed, 11 insertions(+), 15 deletions(-)
Detailed changes
@@ -10,11 +10,7 @@ class CommandList
def self.for(customer, from_jid)
args_for(customer, from_jid).then do |kwargs|
- EMPromise.all(
- @commands.select { |c|
- c.list_for?(**kwargs)
- }.then(&method(:new))
- )
+ new(@commands.select { |c| c.list_for?(**kwargs) })
end
end
@@ -23,13 +19,15 @@ class CommandList
from_jid: from_jid, customer: customer,
tel: customer&.registered? ? customer&.registered?&.phone : nil,
fwd: customer&.fwd, feature_flags: customer&.feature_flags || [],
- payment_methods: [],
- tn_portable: false
+ payment_methods: []
}
return EMPromise.resolve(args) unless customer&.plan_name
- customer.payment_methods.then do |payment_methods|
- args.merge(payment_methods: payment_methods)
+ EMPromise.all([
+ customer.payment_methods,
+ customer.commands
+ ]).then do |(payment_methods, sgx_commands)|
+ args.merge(payment_methods: payment_methods, sgx_commands: sgx_commands)
end
end
@@ -875,12 +875,10 @@ Command.new(
Command.new(
"set-port-out-pin",
"🔐 Set Port-out PIN",
- list_for: lambda do |customer:, **|
- customer.commands.then { |cmds|
- cmds.any? { |item|
- item.node == "set-port-out-pin"
- }
- }.then { customer.active? }
+ list_for: lambda do |sgx_commands:, **|
+ sgx_commands.any? { |item|
+ item.node == "set-port-out-pin"
+ }
end
) {
Command.customer.then do |customer|