Class: Determinator::Retrieve::Routemaster

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/retrieve/routemaster.rb

Overview

A storage and retrieval engine for Determinator using routemaster-drain.

To use this correctly you will need the following environment variables set to appropriate values for your instance of Routemaster:

ROUTEMASTER_CACHE_REDIS ROUTEMASTER_CACHE_AUTH

Constant Summary collapse

CALLBACK_PATH =
(URI.parse(ENV['ROUTEMASTER_CALLBACK_URL']).path rescue '/events').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discovery_url:) ⇒ Routemaster

Returns a new instance of Routemaster.

Parameters:

  • :discovery_url (String)

    The bootstrap URL of the instance of Florence which defines Features.



21
22
23
24
25
26
# File 'lib/determinator/retrieve/routemaster.rb', line 21

def initialize(discovery_url:)
  client = ::Routemaster::APIClient.new(
    response_class: ::Routemaster::Responses::HateoasResponse
  )
  @actor_service = client.discover(discovery_url)
end

Instance Attribute Details

#routemaster_appObject (readonly)

Returns the value of attribute routemaster_app.



16
17
18
# File 'lib/determinator/retrieve/routemaster.rb', line 16

def routemaster_app
  @routemaster_app
end

Instance Method Details

#configure_rails_router(route_mapper) ⇒ Object

Automatically configures the rails router to listen for Features with routemaster

Parameters:

  • route_mapper (ActionDispatch::Routing::Mapper)

    The rails mapper, ‘self’ within the ‘routes.draw` block



44
45
46
# File 'lib/determinator/retrieve/routemaster.rb', line 44

def configure_rails_router(route_mapper)
  route_mapper.mount routemaster_app, at: CALLBACK_PATH
end

#retrieve(name) ⇒ Determinator::Feature?

Retrieves and processes the feature that goes by the given name on this retrieval mechanism.

Returns:



30
31
32
33
34
35
36
37
38
39
# File 'lib/determinator/retrieve/routemaster.rb', line 30

def retrieve(name)
  obj = @actor_service.feature.show(name)
  Determinator::Serializers::JSON.load(obj.body.to_hash)
rescue ::Routemaster::Errors::ResourceNotFound
  # Don't be noisy
  nil
rescue => e
  Determinator.notice_error(e)
  nil
end