Class: Turbo::ScriptMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo/web_view/script_message.rb

Constant Summary collapse

NAMES =
{
  page_loaded: "pageLoaded",
  page_load_failed: "pageLoadFailed",
  error_raised: "errorRaised",
  visit_proposed: "visitProposed",
  visit_started: "visitStarted",
  visit_request_started: "visitRequestStarted",
  visit_request_completed: "visitRequestCompleted",
  visit_request_failed: "visitRequestFailed",
  visit_request_finished: "visitRequestFinished",
  visit_rendered: "visitRendered",
  visit_completed: "visitCompleted",
  form_submission_started: "formSubmissionStarted",
  form_submission_finished: "formSubmissionFinished",
  page_invalidated: "pageInvalidated",
  log: "log"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, data) ⇒ ScriptMessage

Returns a new instance of ScriptMessage.



39
40
41
42
# File 'lib/turbo/web_view/script_message.rb', line 39

def initialize(name, data)
  @name = name
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



37
38
39
# File 'lib/turbo/web_view/script_message.rb', line 37

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



37
38
39
# File 'lib/turbo/web_view/script_message.rb', line 37

def name
  @name
end

Class Method Details

.parse(message) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/turbo/web_view/script_message.rb', line 21

def self.parse(message)
  body = message.body
  return unless body

  rawName = body["name"]
  return unless rawName

  name = NAMES.key(rawName)
  return unless name

  data = body["data"]
  return unless data

  return new(name, data)
end

Instance Method Details

#dateObject



56
57
58
# File 'lib/turbo/web_view/script_message.rb', line 56

def date
  NSDate.alloc.initWithTimeIntervalSince1970(timestamp / 1000.0)
end

#identifierObject



44
45
46
47
# File 'lib/turbo/web_view/script_message.rb', line 44

def identifier
  identifier = data["identifier"]
  identifier if identifier.is_a?(String)
end

#locationObject



65
66
67
# File 'lib/turbo/web_view/script_message.rb', line 65

def location
  NSURL.alloc.initWithString(data["location"]) if data["location"]
end

#optionsObject



69
70
71
72
73
74
75
# File 'lib/turbo/web_view/script_message.rb', line 69

def options
  if options = data["options"]
    VisitOptions.alloc.initFromHash(options)
  else
    nil
  end
end

#restorationIdentifierObject



60
61
62
63
# File 'lib/turbo/web_view/script_message.rb', line 60

def restorationIdentifier
  restorationIdentifier = data["restorationIdentifier"]
  restorationIdentifier if restorationIdentifier.is_a?(String)
end

#timestampObject

Milliseconds since unix epoch as provided by JavaScript Date.now()



50
51
52
53
54
# File 'lib/turbo/web_view/script_message.rb', line 50

def timestamp
  #data["timestamp"] as? TimeInterval ?? 0
  timestamp = data["timestamp"]
  timestamp.to_i || 0
end