Class: Upkeep::Replay::Recipe
- Inherits:
-
Object
- Object
- Upkeep::Replay::Recipe
- Defined in:
- lib/upkeep/replay.rb
Instance Attribute Summary collapse
-
#frame_id ⇒ Object
readonly
Returns the value of attribute frame_id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#replay ⇒ Object
readonly
Returns the value of attribute replay.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#target_id ⇒ Object
readonly
Returns the value of attribute target_id.
-
#target_kind ⇒ Object
readonly
Returns the value of attribute target_kind.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(kind:, frame_id:, target_kind:, target_id:, template: nil, metadata: {}, runtime: nil, replay: nil, &renderer) ⇒ Recipe
constructor
A new instance of Recipe.
- #manifest_reference ⇒ Object
- #manifest_target_render?(target) ⇒ Boolean
- #render ⇒ Object
- #render_target(target) ⇒ Object
- #target_match?(target) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(kind:, frame_id:, target_kind:, target_id:, template: nil, metadata: {}, runtime: nil, replay: nil, &renderer) ⇒ Recipe
Returns a new instance of Recipe.
312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/upkeep/replay.rb', line 312 def initialize(kind:, frame_id:, target_kind:, target_id:, template: nil, metadata: {}, runtime: nil, replay: nil, &renderer) @kind = kind @frame_id = frame_id @target_kind = target_kind @target_id = target_id @template = template @metadata = @runtime = runtime @replay = Replay.payload(replay) @renderer = renderer end |
Instance Attribute Details
#frame_id ⇒ Object (readonly)
Returns the value of attribute frame_id.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def frame_id @frame_id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def @metadata end |
#replay ⇒ Object (readonly)
Returns the value of attribute replay.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def replay @replay end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def runtime @runtime end |
#target_id ⇒ Object (readonly)
Returns the value of attribute target_id.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def target_id @target_id end |
#target_kind ⇒ Object (readonly)
Returns the value of attribute target_kind.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def target_kind @target_kind end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
310 311 312 |
# File 'lib/upkeep/replay.rb', line 310 def template @template end |
Class Method Details
.from_h(snapshot) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/upkeep/replay.rb', line 366 def self.from_h(snapshot) snapshot = Replay.symbolize_keys(snapshot) new( kind: snapshot.fetch(:kind), frame_id: snapshot.fetch(:frame_id), target_kind: snapshot.fetch(:target_kind), target_id: snapshot.fetch(:target_id), template: snapshot[:template], metadata: snapshot.fetch(:metadata), runtime: snapshot[:runtime], replay: snapshot.fetch(:replay, {}) ) end |
Instance Method Details
#manifest_reference ⇒ Object
346 347 348 |
# File 'lib/upkeep/replay.rb', line 346 def manifest_reference [:manifest] || ["manifest"] end |
#manifest_target_render?(target) ⇒ Boolean
342 343 344 |
# File 'lib/upkeep/replay.rb', line 342 def manifest_target_render?(target) !!manifest_reference && target_match?(target) end |
#render ⇒ Object
324 325 326 327 328 |
# File 'lib/upkeep/replay.rb', line 324 def render return @renderer.call if @renderer runtime_renderer.render(self) end |
#render_target(target) ⇒ Object
330 331 332 333 334 335 336 |
# File 'lib/upkeep/replay.rb', line 330 def render_target(target) html = render return html if target_match?(target) require_relative "targeting" Targeting::Extraction.extract_target_html(html, target) end |
#target_match?(target) ⇒ Boolean
338 339 340 |
# File 'lib/upkeep/replay.rb', line 338 def target_match?(target) target && target.kind != "page" && target.kind == target_kind && target.id == target_id end |
#to_h ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/upkeep/replay.rb', line 350 def to_h snapshot = { kind: kind, frame_id: frame_id, target_kind: target_kind, target_id: target_id, template: template, metadata: }.compact snapshot[:runtime] = runtime if runtime replay_snapshot = replay&.to_h snapshot[:replay] = replay_snapshot if replay_snapshot && !replay_snapshot.empty? snapshot end |