1
1
# frozen_string_literal: true
2
2
3
3
module ShopifyApp
4
- class ScripttagsManager
5
- def self . queue ( shop_domain , shop_token , scripttags )
6
- ShopifyApp ::ScripttagsManagerJob . perform_later (
4
+ class ScriptTagsManager
5
+ def self . queue ( shop_domain , shop_token , script_tags )
6
+ ShopifyApp ::ScriptTagsManagerJob . perform_later (
7
7
shop_domain : shop_domain ,
8
8
shop_token : shop_token ,
9
9
# Procs cannot be serialized so we interpolate now, if necessary
10
- scripttags : build_src ( scripttags , shop_domain ) ,
10
+ script_tags : build_src ( script_tags , shop_domain ) ,
11
11
)
12
12
end
13
13
14
- def self . build_src ( scripttags , domain )
15
- scripttags . map do |tag |
14
+ def self . build_src ( script_tags , domain )
15
+ script_tags . map do |tag |
16
16
next tag unless tag [ :src ] . respond_to? ( :call )
17
17
18
18
tag = tag . dup
@@ -21,25 +21,25 @@ def self.build_src(scripttags, domain)
21
21
end
22
22
end
23
23
24
- attr_reader :required_scripttags , :shop_domain
24
+ attr_reader :required_script_tags , :shop_domain
25
25
26
- def initialize ( scripttags , shop_domain )
27
- @required_scripttags = scripttags
26
+ def initialize ( script_tags , shop_domain )
27
+ @required_script_tags = script_tags
28
28
@shop_domain = shop_domain
29
29
@session = nil
30
30
end
31
31
32
- def recreate_scripttags !( session :)
33
- destroy_scripttags ( session : session )
34
- create_scripttags ( session : session )
32
+ def recreate_script_tags !( session :)
33
+ destroy_script_tags ( session : session )
34
+ create_script_tags ( session : session )
35
35
end
36
36
37
- def create_scripttags ( session :)
37
+ def create_script_tags ( session :)
38
38
@session = session
39
- return unless required_scripttags . present?
39
+ return unless required_script_tags . present?
40
40
41
41
# Check if any scripttag has template_types defined
42
- template_types_to_check = required_scripttags . flat_map { |tag | tag [ :template_types ] } . compact . uniq
42
+ template_types_to_check = required_script_tags . flat_map { |tag | tag [ :template_types ] } . compact . uniq
43
43
44
44
# If template types are specified, check if the theme supports app blocks for those templates
45
45
if template_types_to_check . any?
@@ -59,19 +59,19 @@ def create_scripttags(session:)
59
59
end
60
60
end
61
61
62
- expanded_scripttags . each do |scripttag |
63
- create_scripttag ( scripttag ) unless scripttag_exists? ( scripttag [ :src ] )
62
+ expanded_script_tags . each do |script_tag |
63
+ create_script_tag ( script_tag ) unless script_tag_exists? ( script_tag [ :src ] )
64
64
end
65
65
end
66
66
67
- def destroy_scripttags ( session :)
67
+ def destroy_script_tags ( session :)
68
68
@session = session
69
- scripttags = expanded_scripttags
70
- fetch_all_scripttags . each do |tag |
71
- delete_scripttag ( tag ) if required_scripttag? ( scripttags , tag )
69
+ script_tags = expanded_script_tags
70
+ fetch_all_script_tags . each do |tag |
71
+ delete_script_tag ( tag ) if required_script_tag? ( script_tags , tag )
72
72
end
73
73
74
- @current_scripttags = nil
74
+ @current_script_tags = nil
75
75
end
76
76
77
77
private
@@ -236,15 +236,15 @@ def template_supports_app_blocks?(theme_id, template_type)
236
236
end
237
237
end
238
238
239
- def expanded_scripttags
240
- self . class . build_src ( required_scripttags , shop_domain )
239
+ def expanded_script_tags
240
+ self . class . build_src ( required_script_tags , shop_domain )
241
241
end
242
242
243
- def required_scripttag? ( scripttags , tag )
244
- scripttags . map { |w | w [ :src ] } . include? ( tag [ "src" ] )
243
+ def required_script_tag? ( script_tags , tag )
244
+ script_tags . map { |w | w [ :src ] } . include? ( tag [ "src" ] )
245
245
end
246
246
247
- def create_scripttag ( attributes )
247
+ def create_script_tag ( attributes )
248
248
client = graphql_client
249
249
250
250
variables = {
@@ -287,7 +287,7 @@ def create_scripttag(attributes)
287
287
end
288
288
end
289
289
290
- def delete_scripttag ( tag )
290
+ def delete_script_tag ( tag )
291
291
client = graphql_client
292
292
293
293
query = <<~QUERY
@@ -311,15 +311,15 @@ def delete_scripttag(tag)
311
311
end
312
312
end
313
313
314
- def scripttag_exists ?( src )
315
- current_scripttags [ src ]
314
+ def script_tag_exists ?( src )
315
+ current_script_tags [ src ]
316
316
end
317
317
318
- def current_scripttags
319
- @current_scripttags ||= fetch_all_scripttags . index_by { |tag | tag [ "src" ] }
318
+ def current_script_tags
319
+ @current_script_tags ||= fetch_all_script_tags . index_by { |tag | tag [ "src" ] }
320
320
end
321
321
322
- def fetch_all_scripttags
322
+ def fetch_all_script_tags
323
323
client = graphql_client
324
324
325
325
query = <<~QUERY
0 commit comments