module Yrpc module Controllers class Base include ActiveSupport::Callbacks define_callbacks :call attr_reader :request def initialize(method_key:, service:, rpc_desc:, active_call:, message:) @request = Request.new( method_key: method_key, service: service, rpc_desc: rpc_desc, active_call: active_call, message: message ) end def self.before_action(methods) [*methods].each do |method| set_callback :call, :before, method end end def self.after_action(methods) [*methods].each do |method| set_callback :call, :after, method end end def self.bind(service_class) Yrpc.services << service_class.name.constantize ServiceBinder.new(service_class).bind!(self) end def call(method_key, &block) run_callbacks :call do send(method_key, &block) end end end end end