Class: Api::Vendor::V1::Klook::BookingSerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- Api::Vendor::V1::Klook::BookingSerializer
- Includes:
- Concerns::SerializerUtils
- Defined in:
- app/serializers/api/vendor/v1/klook/booking_serializer.rb
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(reservation_or_reservations, options = {}) ⇒ BookingSerializer
constructor
A new instance of BookingSerializer.
Methods inherited from BaseSerializer
Constructor Details
#initialize(reservation_or_reservations, options = {}) ⇒ BookingSerializer
Returns a new instance of BookingSerializer.
5 6 7 8 9 10 |
# File 'app/serializers/api/vendor/v1/klook/booking_serializer.rb', line 5 def initialize(reservation_or_reservations, = {}) super() # Accepts either a single reservation object or an array of reservations. @reservations = reservation_or_reservations @options = end |
Instance Method Details
#as_json ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/serializers/api/vendor/v1/klook/booking_serializer.rb', line 12 def as_json(*) if @options[:route] == 'bookings-list' @reservations.map { |reservation| serialize_booking(reservation.decorate) } else if @options[:route] == 'booking-detail' return {} if @reservations.blank? reservation = @reservations.first else reservation = @reservations end serialize_booking(reservation.decorate) end end |