Sha256: 29b533ff624a4ebf7ca4bbcb84f5312dffc0eb991719f34b60bc2b5a99b0701f

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require_relative "identity_processor"

module PageEz
  module MethodGenerators
    class DefineHasManyResultMethods
      def initialize(name, evaluator_class:, constructor:, processor: IdentityProcessor)
        @name = name
        @evaluator_class = evaluator_class
        @constructor = constructor
        @processor = processor
      end

      def run(target)
        name = @name
        evaluator_class = @evaluator_class
        constructor = @constructor
        processor = @processor

        target.logged_define_method(name) do |*args|
          evaluator = evaluator_class.run(processor.run_args(args), target: self)

          selector = processor.selector(evaluator.selector, args)

          PageEz.reraise_selector_error(selector) do
            PageEz::HasManyResult.new(
              container: container,
              selector: selector,
              options: evaluator.options,
              constructor: constructor.method(:new)
            )
          end
        end

        target.logged_define_method("has_#{name}_count?") do |count, *args|
          send(name, *args).has_count_of?(count)
        end

        target.logged_define_method("has_#{name}?") do |*args|
          send(name, *args).has_any_elements?
        end

        target.logged_define_method("has_no_#{name}?") do |*args|
          send(name, *args).has_no_elements?
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
page_ez-0.2.0 lib/page_ez/method_generators/define_has_many_result_methods.rb
page_ez-0.1.0 lib/page_ez/method_generators/define_has_many_result_methods.rb