Class: ShopifyApp::ScripttagsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_app/scripttags_manager.rb

Defined Under Namespace

Classes: CreationFailed

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scripttags) ⇒ ScripttagsManager

Returns a new instance of ScripttagsManager.



15
16
17
# File 'lib/shopify_app/scripttags_manager.rb', line 15

def initialize(scripttags)
  @required_scripttags = scripttags
end

Instance Attribute Details

#required_scripttagsObject (readonly)

Returns the value of attribute required_scripttags.



13
14
15
# File 'lib/shopify_app/scripttags_manager.rb', line 13

def required_scripttags
  @required_scripttags
end

Class Method Details

.queue(shop_domain, shop_token, scripttags) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/shopify_app/scripttags_manager.rb', line 5

def self.queue(shop_domain, shop_token, scripttags)
  ShopifyApp::ScripttagsManagerJob.perform_later(
    shop_domain: shop_domain,
    shop_token: shop_token,
    scripttags: scripttags
  )
end

Instance Method Details

#create_scripttagsObject



24
25
26
27
28
29
30
# File 'lib/shopify_app/scripttags_manager.rb', line 24

def create_scripttags
  return unless required_scripttags.present?

  required_scripttags.each do |scripttag|
    create_scripttag(scripttag) unless scripttag_exists?(scripttag[:src])
  end
end

#destroy_scripttagsObject



32
33
34
35
36
37
38
# File 'lib/shopify_app/scripttags_manager.rb', line 32

def destroy_scripttags
  ShopifyAPI::ScriptTag.all.each do |scripttag|
    ShopifyAPI::ScriptTag.delete(scripttag.id) if is_required_scripttag?(scripttag)
  end

  @current_scripttags = nil
end

#recreate_scripttags!Object



19
20
21
22
# File 'lib/shopify_app/scripttags_manager.rb', line 19

def recreate_scripttags!
  destroy_scripttags
  create_scripttags
end