60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/upkeep/replay.rb', line 60
def from_h(snapshot)
return snapshot if snapshot.is_a?(Value)
return LiteralValue.new(value: snapshot) unless snapshot.is_a?(Hash)
snapshot = Replay.symbolize_keys(snapshot)
case snapshot.fetch(:type).to_s
when "active_record"
ActiveRecordValue.new(
model: snapshot.fetch(:model),
id: snapshot.fetch(:id)
)
when "active_record_relation"
ActiveRecordRelationValue.new(
model: snapshot.fetch(:model),
sql: snapshot.fetch(:sql),
primary_key: snapshot[:primary_key],
appendable: snapshot.fetch(:appendable),
limit_value: snapshot.fetch(:limit_value),
predicates: snapshot.fetch(:predicates),
member_ids: snapshot.fetch(:member_ids)
)
when "array"
ArrayValue.new(items: snapshot.fetch(:items).map { |item| from_h(item) })
when "hash"
HashValue.new(entries: Replay.value_hash_from_h(snapshot.fetch(:entries)))
when "literal"
LiteralValue.new(value: snapshot[:value])
when "unsupported"
UnsupportedValue.new(class_name: snapshot.fetch(:class))
when "refused_active_record_relation"
RefusedActiveRecordRelationValue.new(
model: snapshot.fetch(:model),
sql_digest: snapshot.fetch(:sql_digest),
reason: snapshot.fetch(:reason)
)
else
raise ArgumentError, "unknown replay value type: #{snapshot.fetch(:type).inspect}"
end
end
|