Class: PageEz::MethodGenerators::DefineHasOneResultMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/page_ez/method_generators/define_has_one_result_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, evaluator_class:, constructor:, processor: IdentityProcessor) ⇒ DefineHasOneResultMethods

Returns a new instance of DefineHasOneResultMethods.



6
7
8
9
10
11
# File 'lib/page_ez/method_generators/define_has_one_result_methods.rb', line 6

def initialize(name, evaluator_class:, constructor:, processor: IdentityProcessor)
  @name = name
  @evaluator_class = evaluator_class
  @processor = processor
  @constructor = constructor
end

Instance Method Details

#run(target) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/page_ez/method_generators/define_has_one_result_methods.rb', line 13

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

  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::HasOneResult.new(
        container: container,
        selector: selector,
        options: evaluator.options,
        constructor: constructor.method(:new)
      )
    end
  end
end