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.
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/upkeep/replay.rb', line 343 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.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def frame_id @frame_id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def kind @kind end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def @metadata end |
#replay ⇒ Object (readonly)
Returns the value of attribute replay.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def replay @replay end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def runtime @runtime end |
#target_id ⇒ Object (readonly)
Returns the value of attribute target_id.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def target_id @target_id end |
#target_kind ⇒ Object (readonly)
Returns the value of attribute target_kind.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def target_kind @target_kind end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
341 342 343 |
# File 'lib/upkeep/replay.rb', line 341 def template @template end |
Class Method Details
.from_h(snapshot) ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/upkeep/replay.rb', line 397 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
377 378 379 |
# File 'lib/upkeep/replay.rb', line 377 def manifest_reference [:manifest] || ["manifest"] end |
#manifest_target_render?(target) ⇒ Boolean
373 374 375 |
# File 'lib/upkeep/replay.rb', line 373 def manifest_target_render?(target) !!manifest_reference && target_match?(target) end |
#render ⇒ Object
355 356 357 358 359 |
# File 'lib/upkeep/replay.rb', line 355 def render return @renderer.call if @renderer runtime_renderer.render(self) end |
#render_target(target) ⇒ Object
361 362 363 364 365 366 367 |
# File 'lib/upkeep/replay.rb', line 361 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
369 370 371 |
# File 'lib/upkeep/replay.rb', line 369 def target_match?(target) target && target.kind != "page" && target.kind == target_kind && target.id == target_id end |
#to_h ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/upkeep/replay.rb', line 381 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 |