Class: Surfliner::MetadataConsumer::Solr::MessageHandler
- Inherits:
-
Object
- Object
- Surfliner::MetadataConsumer::Solr::MessageHandler
- Defined in:
- lib/surfliner/metadata_consumer/solr/message_handler.rb
Overview
A message handler that delegates to sub-handlers based on the resource status provided in the message.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Class Method Summary collapse
-
.handle(payload_json) ⇒ Object
Delegates payload handling to the appropriate handler.
-
.handler_for(payload_json) ⇒ #handle
Returns the appropriate handler based on the resource status provided in the message.
Instance Method Summary collapse
-
#handle ⇒ Object
abstract
Implementations should handle the
Payloadprovided in the initializer. -
#initialize(payload) ⇒ MessageHandler
constructor
Initializes a new
MessageHandler. -
#solr_connection ⇒ RSolr::Client
Connects to the configured Solr instance.
Constructor Details
#initialize(payload) ⇒ MessageHandler
Initializes a new MessageHandler.
51 52 53 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 51 def initialize(payload) @payload = payload end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
10 11 12 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 10 def payload @payload end |
Class Method Details
.handle(payload_json) ⇒ Object
Delegates payload handling to the appropriate handler.
44 45 46 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 44 def handle(payload_json) handler_for(payload_json).handle end |
.handler_for(payload_json) ⇒ #handle
Returns the appropriate handler based on the resource status provided in the message.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 29 def handler_for(payload_json) payload = Payload.new(payload_json) case payload.status when :published, :updated IndexHandler.new(payload) when :unpublished, :deleted DeleteHandler.new(payload) else raise ArgumentError, "Couldn't handle message with payload status: #{payload.status}" end end |
Instance Method Details
#handle ⇒ Object
This method is abstract.
Implementations should handle the Payload provided in the initializer.
57 58 59 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 57 def handle raise NotImplementedError end |
#solr_connection ⇒ RSolr::Client
Connects to the configured Solr instance.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/surfliner/metadata_consumer/solr/message_handler.rb', line 14 def solr_connection @solr_connection ||= begin solr_host = ENV.fetch("SOLR_HOST") solr_port = ENV.fetch("SOLR_PORT") solr_collection_name = ENV.fetch("SOLR_COLLECTION_NAME") solr_url = "http://#{solr_auth}#{solr_host}:#{solr_port}/solr/#{solr_collection_name}" RSolr.connect(url: solr_url) end end |