Class: Igniter::Store::Protocol::Handlers::ProjectionHandler
- Inherits:
-
Object
- Object
- Igniter::Store::Protocol::Handlers::ProjectionHandler
- Defined in:
- lib/igniter/store/protocol/handlers/projection_handler.rb
Instance Method Summary collapse
- #call(descriptor) ⇒ Object
-
#initialize(store) ⇒ ProjectionHandler
constructor
A new instance of ProjectionHandler.
Constructor Details
#initialize(store) ⇒ ProjectionHandler
Returns a new instance of ProjectionHandler.
8 |
# File 'lib/igniter/store/protocol/handlers/projection_handler.rb', line 8 def initialize(store) = @store = store |
Instance Method Details
#call(descriptor) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/igniter/store/protocol/handlers/projection_handler.rb', line 10 def call(descriptor) return Receipt.rejection("Missing required fields: name", kind: :projection) if descriptor[:name].nil? if descriptor[:reads].nil? && descriptor[:source].nil? return Receipt.rejection("Missing required fields: reads or source", kind: :projection) end name = descriptor[:name].to_sym source = descriptor[:source] reads = descriptor[:reads] || source reads = Array(reads).map(&:to_sym) relations = Array(descriptor[:relations]).map(&:to_sym) consumer_hint = (descriptor[:consumer_hint] || :protocol_client).to_sym mode = descriptor.fetch(:mode, :on_demand) reactive = descriptor.key?(:reactive) ? !!descriptor[:reactive] : mode == :materialized @store.register_projection( ProjectionPath.new( name: name, reads: reads, relations: relations, consumer_hint: consumer_hint, reactive: reactive ) ) Receipt.accepted(kind: :projection, name: name) end |