Class: PwaManifestGenerator::UrlHandler

Inherits:
Object
  • Object
show all
Includes:
Freezeable
Defined in:
lib/pwa_manifest_generator/url_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Freezeable

included

Constructor Details

#initializeUrlHandler

Returns a new instance of UrlHandler.



11
12
13
# File 'lib/pwa_manifest_generator/url_handler.rb', line 11

def initialize
  @scope = Struct.new(:matches, :launch_url).new([], 'https://localhost:3000')
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



9
10
11
# File 'lib/pwa_manifest_generator/url_handler.rb', line 9

def scope
  @scope
end

Instance Method Details

#to_htmlObject



22
23
24
25
26
27
28
29
30
# File 'lib/pwa_manifest_generator/url_handler.rb', line 22

def to_html
  json = {
    scope: {
      matches: @scope.matches,
      launch_url: @scope.launch_url
    }
  }.to_json
  json.respond_to?(:html_safe) ? json.html_safe : json
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/pwa_manifest_generator/url_handler.rb', line 15

def valid?
  @scope.matches.all? do |match|
    match.is_a?(String) && match.start_with?('http://', 'https://')
  end &&
    @scope.launch_url.is_a?(String) && @scope.launch_url.start_with?('http://', 'https://')
end