Class: MingleEvents::Processors::CardData
- Inherits:
-
Object
- Object
- MingleEvents::Processors::CardData
- Defined in:
- lib/mingle_events/processors/card_data.rb
Overview
Provides ability to lookup card data, e.g., card’s type name, for any card serving as a source for the stream of events. Implements two interfaces: the standard event processing interface, handle_events, and also, for_card_event, which returns of has of card data for the given event. See the project README for additional information on using this class in a processing pipeline.
Instance Method Summary collapse
-
#for_card_event(card_event) ⇒ Object
Return a hash of data for the card that sourced the passed event.
-
#initialize(mingle_access, project_identifier, custom_properties = ProjectCustomProperties.new(mingle_access, project_identifier)) ⇒ CardData
constructor
A new instance of CardData.
-
#process_events(events) ⇒ Object
Capture which events are card events and might require data lookup.
Constructor Details
#initialize(mingle_access, project_identifier, custom_properties = ProjectCustomProperties.new(mingle_access, project_identifier)) ⇒ CardData
Returns a new instance of CardData.
11 12 13 14 15 16 |
# File 'lib/mingle_events/processors/card_data.rb', line 11 def initialize(mingle_access, project_identifier, custom_properties = ProjectCustomProperties.new(mingle_access, project_identifier)) @mingle_access = mingle_access @project_identifier = project_identifier @custom_properties = custom_properties @card_data_by_number_and_version = nil end |
Instance Method Details
#for_card_event(card_event) ⇒ Object
Return a hash of data for the card that sourced the passed event. The data will be for the version of the card that was created by the event and not the current state of the card. Currently supported data keys are: :number, :version, :card_type_name
29 30 31 32 33 34 35 |
# File 'lib/mingle_events/processors/card_data.rb', line 29 def for_card_event(card_event) if @card_data_by_number_and_version.nil? load_bulk_card_data end key = data_key(card_event.card_number, card_event.version) @card_data_by_number_and_version[key] ||= load_card_data_for_event(card_event) end |
#process_events(events) ⇒ Object
Capture which events are card events and might require data lookup. The actual data retrieval is lazy and will only occur as needed.
20 21 22 23 |
# File 'lib/mingle_events/processors/card_data.rb', line 20 def process_events(events) @card_events = events.select(&:card?) events end |