Module: EventHookClientServer::Server::DefinitionHelpers

Included in:
EventHookClientServer::Server
Defined in:
lib/event_hook_client_server/server/definition_helpers.rb

Instance Method Summary collapse

Instance Method Details

#generic_rpc(name, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/event_hook_client_server/server/definition_helpers.rb', line 4

def generic_rpc(name, options = {})
  [[:create_], [:update_], [:destroy_], [], [nil, :s]]
    .compact.each do |prefix, suffix|
      method_name = [prefix, name, suffix].compact.join
      handler_name = "#{method_name}_handler".to_sym

      attr_accessor handler_name

      # NOTE: this is ugly, but it's (performance wise) much faster than
      # define_method
      method_definition = <<-RUBY
        def #{method_name}(input, request)
          process_request(:#{method_name}, input, request)
        end
      RUBY

      class_eval(method_definition, __FILE__, __LINE__ - 5)
    end
end