Class: Trane::Docs::ServiceDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/trane/docs/service_definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes, service_name:) ⇒ ServiceDefinition

Returns a new instance of ServiceDefinition.



19
20
21
22
23
# File 'lib/trane/docs/service_definition.rb', line 19

def initialize(routes, service_name:)
  @routes       = routes
  @service_name = service_name
  @registry     = Trane.registry
end

Class Method Details

.generate(routes, service_name:) ⇒ Hash

Generate a complete service definition hash from the registry and routes.

Parameters:

  • routes (ActionDispatch::Routing::RouteSet::NamedRouteCollection, Array)

    Rails routes

  • service_name (String)

    published as service.name. Trane does not configure the API name: callers inside a Rails application pass Rails.application.name. Required — there is no default.

Returns:

  • (Hash)


15
16
17
# File 'lib/trane/docs/service_definition.rb', line 15

def self.generate(routes, service_name:)
  new(routes, service_name: service_name).to_h
end

Instance Method Details

#to_hObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/trane/docs/service_definition.rb', line 25

def to_h
  {
    service: {
      name: @service_name
    },
    operations: build_operations,
    representations: build_representations,
    errors: build_errors
  }
end