8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/upkeep/replay.rb', line 8
def from_h(snapshot)
return snapshot if snapshot.is_a?(Payload)
snapshot = Replay.symbolize_keys(snapshot || {})
return Empty.new if snapshot.empty?
case snapshot.fetch(:type).to_s
when "controller_page"
ControllerPage.new(
controller_class: snapshot[:controller_class],
action: snapshot.fetch(:action),
env: snapshot.fetch(:env)
)
when "template"
Template.new(
controller_class: snapshot[:controller_class],
template: snapshot.fetch(:template),
locals: Replay.value_hash_from_h(snapshot.fetch(:locals))
)
when "fragment"
Fragment.new(
controller_class: snapshot[:controller_class],
template: snapshot.fetch(:template),
locals: Replay.value_hash_from_h(snapshot.fetch(:locals))
)
when "collection"
Collection.new(
controller_class: snapshot[:controller_class],
partial: snapshot.fetch(:partial),
collection: Value.from_h(snapshot.fetch(:collection)),
options: Replay.value_hash_from_h(snapshot.fetch(:options))
)
when "collection_member"
CollectionMember.new(
controller_class: snapshot[:controller_class],
partial: snapshot.fetch(:partial),
record: Value.from_h(snapshot.fetch(:record)),
options: Replay.value_hash_from_h(snapshot.fetch(:options))
)
else
raise ArgumentError, "unknown replay payload type: #{snapshot.fetch(:type).inspect}"
end
end
|