Class: RailsTwirp::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_twirp/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(route_set) ⇒ Mapper

Returns a new instance of Mapper.



57
58
59
60
# File 'lib/rails_twirp/mapper.rb', line 57

def initialize(route_set)
  @route_set = route_set
  @module = nil
end

Instance Method Details

#scope(**options) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/rails_twirp/mapper.rb', line 68

def scope(**options)
  last_module = @module
  if (modyoule = options.delete(:module))
    @module = @module.nil? ? modyoule : "#{@module}/#{modyoule}"
  end
  raise ArgumentError, "Unknown scope argument #{options.keys.first}" unless options.empty?
  yield
ensure
  @module = last_module
end

#service(service_definition, **kwargs, &block) ⇒ Object



62
63
64
65
66
# File 'lib/rails_twirp/mapper.rb', line 62

def service(service_definition, **kwargs, &block)
  service_route_set = @route_set.services[service_definition]
  service_mapper = ServiceMapper.new(service_route_set, self)
  scope(**kwargs) { service_mapper.instance_exec(&block) }
end