Class: ShopifyApp::ScripttagsManager
- Inherits:
-
Object
- Object
- ShopifyApp::ScripttagsManager
- Defined in:
- lib/shopify_app/managers/scripttags_manager.rb
Defined Under Namespace
Classes: CreationFailed
Instance Attribute Summary collapse
-
#required_scripttags ⇒ Object
readonly
Returns the value of attribute required_scripttags.
-
#shop_domain ⇒ Object
readonly
Returns the value of attribute shop_domain.
Class Method Summary collapse
Instance Method Summary collapse
- #create_scripttags ⇒ Object
- #destroy_scripttags ⇒ Object
-
#initialize(scripttags, shop_domain) ⇒ ScripttagsManager
constructor
A new instance of ScripttagsManager.
- #recreate_scripttags! ⇒ Object
Constructor Details
#initialize(scripttags, shop_domain) ⇒ ScripttagsManager
Returns a new instance of ScripttagsManager.
26 27 28 29 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 26 def initialize(, shop_domain) @required_scripttags = @shop_domain = shop_domain end |
Instance Attribute Details
#required_scripttags ⇒ Object (readonly)
Returns the value of attribute required_scripttags.
24 25 26 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 24 def @required_scripttags end |
#shop_domain ⇒ Object (readonly)
Returns the value of attribute shop_domain.
24 25 26 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 24 def shop_domain @shop_domain end |
Class Method Details
.build_src(scripttags, domain) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 15 def self.build_src(, domain) .map do |tag| next tag unless tag[:src].respond_to?(:call) tag = tag.dup tag[:src] = tag[:src].call(domain) tag end end |
.queue(shop_domain, shop_token, scripttags) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 6 def self.queue(shop_domain, shop_token, ) ShopifyApp::ScripttagsManagerJob.perform_later( shop_domain: shop_domain, shop_token: shop_token, # Procs cannot be serialized so we interpolate now, if necessary scripttags: build_src(, shop_domain) ) end |
Instance Method Details
#create_scripttags ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 36 def return unless .present? .each do |scripttag| create_scripttag(scripttag) unless scripttag_exists?(scripttag[:src]) end end |
#destroy_scripttags ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 44 def = ShopifyAPI::ScriptTag.all.each do |tag| ShopifyAPI::ScriptTag.delete(tag.id) if required_scripttag?(, tag) end @current_scripttags = nil end |
#recreate_scripttags! ⇒ Object
31 32 33 34 |
# File 'lib/shopify_app/managers/scripttags_manager.rb', line 31 def end |