Class: Spree::Adyen::Presenters::Communication

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/models/spree/adyen/presenters/communication.rb

Overview

Factory for creating communication presenters, based on a payment source.

Constant Summary collapse

PRESENTERS =
[
  ::Spree::Adyen::Presenters::Communications::AdyenNotification,
  ::Spree::Adyen::Presenters::Communications::HppSource,
  ::Spree::Adyen::Presenters::Communications::LogEntry
].freeze

Class Method Summary collapse

Class Method Details

.build(object) ⇒ Object



19
20
21
# File 'app/models/spree/adyen/presenters/communication.rb', line 19

def self.build object
  presenter_for(object).new(object)
end

.from_source(source) ⇒ Object



13
14
15
16
17
# File 'app/models/spree/adyen/presenters/communication.rb', line 13

def self.from_source source
  ([source] + source.notifications + source.payment.log_entries).
    sort_by(&:created_at).
    map { |x| build x }
end

.presenter_for(object) ⇒ Object



23
24
25
26
27
# File 'app/models/spree/adyen/presenters/communication.rb', line 23

def self.presenter_for object
  PRESENTERS.detect do |klass|
    klass.applicable? object
  end || fail("Couldn't map to a communication type")
end