Sha256: dc68e6eb28382b465528269d15bbf42c3c38563042ee35dfd5b02525f575d20e

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ampedxx-yrpc-0.1.6 lib/yrpc/controllers/base.rb
ampedxx-yrpc-0.1.4 lib/yrpc/controllers/base.rb