Module: DiscoApp::Concerns::ShopUpdateJob

Extended by:
ActiveSupport::Concern
Included in:
ShopUpdateJob
Defined in:
app/jobs/disco_app/concerns/shop_update_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(_shop, shop_data = nil) ⇒ Object

Perform an update of the current shop’s information.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/jobs/disco_app/concerns/shop_update_job.rb', line 6

def perform(_shop, shop_data = nil)
  # If we weren't provided with shop data (eg from a webhook), fetch it.
  shop_data ||= JSON.parse(ShopifyAPI::Shop.current.to_json)

  # Update attributes stored directly on the Shop model, along with the data hash itself.
  @shop.update(
    shop_data
      .with_indifferent_access
      .slice(*DiscoApp::Shop.column_names)
      .except(:id, :created_at)
      .merge(data: shop_data)
  )
end