Sha256: 7ea702350eac62bedd70de094b1bb8a9354d207fcc11983e7367f4e5fcd353ea

Contents?: true

Size: 1.03 KB

Versions: 12

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module PageMagic
  # class WatchedElementDefinition - Contains the specification the for checking if an subject has changed
  class Watcher
    attr_reader :name, :context, :observed_value, :block

    # @param [Symbol] name the of the subject being checked
    # @example
    #  Watcher.new(:url) do
    #    session.url
    #  end
    def initialize(name, context:, &block)
      @name = name
      @context = context
      @block = block
    end

    # check current value of watched element. The result of the check can be accessed
    # by calling {PageMagic::Watcher#last}
    # if a block was specified to the constructor then this will be executed.
    # @return [PageMagic::Watcher]
    def check
      @observed_value = context.instance_eval(&block)
      self
    end

    # @param [Object] other candidate for equality check
    # @return [Boolen] true of the candiate is equal ot this one.
    def ==(other)
      other.is_a?(Watcher) &&
        name == other.name &&
        block == other.block
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
page_magic-2.0.13 lib/page_magic/watcher.rb
page_magic-2.0.12 lib/page_magic/watcher.rb
page_magic-2.0.11 lib/page_magic/watcher.rb
page_magic-2.0.10 lib/page_magic/watcher.rb
page_magic-2.0.9 lib/page_magic/watcher.rb
page_magic-2.0.6 lib/page_magic/watcher.rb
page_magic-2.0.5 lib/page_magic/watcher.rb
page_magic-2.0.4 lib/page_magic/watcher.rb
page_magic-2.0.3 lib/page_magic/watcher.rb
page_magic-2.0.2 lib/page_magic/watcher.rb
page_magic-2.0.1 lib/page_magic/watcher.rb
page_magic-2.0.0 lib/page_magic/watcher.rb