Class: Determinator::Retrieve::Routemaster
- Inherits:
-
Object
- Object
- Determinator::Retrieve::Routemaster
- 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
-
#routemaster_app ⇒ Object
readonly
Returns the value of attribute routemaster_app.
Instance Method Summary collapse
-
#configure_rails_router(route_mapper) ⇒ Object
Automatically configures the rails router to listen for Features with routemaster.
-
#initialize(discovery_url:) ⇒ Routemaster
constructor
A new instance of Routemaster.
-
#retrieve(name) ⇒ Determinator::Feature?
Retrieves and processes the feature that goes by the given name on this retrieval mechanism.
Constructor Details
#initialize(discovery_url:) ⇒ Routemaster
Returns a new instance of Routemaster.
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_app ⇒ Object (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
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.
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 |