Sha256: d4d1b47bd5cdca0d43b36d44dc57c9de4c93b592d12d0518a469728b9901e627
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true module Protoboard ## # This module is responsible to manage a proxy module that executes the circuit. module CircuitProxyFactory class << self using Protoboard::Refinements::StringExtensions ## # Creates the module that executes the circuit def create_module(circuits, class_name) module_name = infer_module_name(class_name, circuits.map(&:method_name)) proxy_module = Module.new proxy_module.instance_exec do circuits.each do |circuit| define_method(circuit.method_name) do |*args| Protoboard.config.adapter.run_circuit(circuit) { super(*args) } end end end Protoboard.const_set(module_name, proxy_module) end private ## # Formats the module name def infer_module_name(class_name, methods) "#{methods.map(&:to_s).map { |method| method.camelize }.join}#{class_name.split('::').join('')}CircuitProxy" end end end end
Version data entries
5 entries across 5 versions & 1 rubygems