Class: Rooftop::SpektrixSync::InstanceSync
- Inherits:
-
Object
- Object
- Rooftop::SpektrixSync::InstanceSync
- Defined in:
- lib/rooftop/spektrix_sync/lib/instance_sync.rb
Instance Method Summary collapse
-
#initialize(spektrix_instance, event_sync) ⇒ InstanceSync
constructor
A new instance of InstanceSync.
- #sync ⇒ Object
Constructor Details
#initialize(spektrix_instance, event_sync) ⇒ InstanceSync
Returns a new instance of InstanceSync.
5 6 7 8 9 10 11 12 13 |
# File 'lib/rooftop/spektrix_sync/lib/instance_sync.rb', line 5 def initialize(spektrix_instance, event_sync) @spektrix_instance_statuses = event_sync.spektrix_instance_statuses @spektrix_event = event_sync.spektrix_event @rooftop_event = event_sync.rooftop_event @logger = event_sync.logger @spektrix_instance = spektrix_instance @rooftop_instance = find_rooftop_instance_by_spektrix_id(@spektrix_instance.id) || @rooftop_event.instances.build(status: nil, meta_attributes: {}) @rooftop_price_lists = event_sync.rooftop_price_lists end |
Instance Method Details
#sync ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rooftop/spektrix_sync/lib/instance_sync.rb', line 15 def sync # This is a bit of a hack: we have to create a new instance and assign all the attributes from the old one, so it has an _event_id param. if @rooftop_instance.persisted? @rooftop_instance = @rooftop_event.instances.build(@rooftop_instance.attributes) instance_updated = true end update_price if @rooftop_instance.price_list_id.nil? @logger.error("[spektrix] No price list for Spektrix instance id #{@spektrix_instance.id}") return end update_availability update_on_sale if event_instance_requires_sync? @rooftop_instance.[:spektrix_hash] = generate_spektrix_hash(@spektrix_instance) if @rooftop_instance.save! @logger.info("[spektrix] #{instance_updated ? "Updated" : "Created"} Rooftop instance #{@rooftop_instance.id}") return @rooftop_instance.id else @logger.error("[spektrix] Couldn't save Rooftop instance #{@rooftop_instance.id}") end else @logger.info("[spektrix] Skipping event instance save - computed hash matched") return nil end end |