Module: Protoplasm::Types::ClassMethods

Defined in:
lib/protoplasm/types/types.rb

Instance Method Summary collapse

Instance Method Details

#request_class(request_class = nil) ⇒ Object



29
30
31
# File 'lib/protoplasm/types/types.rb', line 29

def request_class(request_class = nil)
  request_class ? @request_class = request_class : @request_class
end

#request_type(request_obj) ⇒ Object



33
34
35
# File 'lib/protoplasm/types/types.rb', line 33

def request_type(request_obj)
  request_obj.send(@request_type_field)
end

#request_type_field(field = nil) ⇒ Object



37
38
39
# File 'lib/protoplasm/types/types.rb', line 37

def request_type_field(field = nil)
  field ? @request_type_field = field : @request_type_field
end

#request_type_for_field(field) ⇒ Object



50
51
52
# File 'lib/protoplasm/types/types.rb', line 50

def request_type_for_field(field)
  @response_map_by_field[field]
end

#request_type_for_request(req) ⇒ Object



54
55
56
# File 'lib/protoplasm/types/types.rb', line 54

def request_type_for_request(req)
  @response_map_by_type[req.send(@request_type_field)]
end

#rpc_map(type, field, response_class, opts = nil) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/protoplasm/types/types.rb', line 41

def rpc_map(type, field, response_class, opts = nil)
  @response_map_by_field ||= {}
  @response_map_by_type ||= {}
  streaming = opts && opts.key?(:streaming) ? opts[:streaming] : false
  rrt = RequestResponseType.new(@request_class, response_class, type, field, streaming)
  @response_map_by_field[field] = rrt
  @response_map_by_type[type] = rrt
end