Class: PageEz::MethodGenerators::HasOneComposedClass

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, composed_class, options, &block) ⇒ HasOneComposedClass

Returns a new instance of HasOneComposedClass.



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

def initialize(name, composed_class, options, &block)
  @name = name
  @composed_class = composed_class
  @options = options
  @block = block
end

Instance Attribute Details

#selectorObject (readonly)

Returns the value of attribute selector.



4
5
6
# File 'lib/page_ez/method_generators/has_one_composed_class.rb', line 4

def selector
  @selector
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
33
34
35
36
37
# File 'lib/page_ez/method_generators/has_one_composed_class.rb', line 13

def run(target)
  constructor = target.constructor_from_block(@composed_class, &@block)

  base_selector = @options.delete(:base_selector)

  target.logged_define_method(@name) do |*args|
    if base_selector
      Class.new(constructor).tap do |new_constructor|
        new_constructor.base_selector base_selector
      end.new(self)
    else
      constructor.new(self)
    end
  end

  if base_selector
    evaluator_class = SelectorEvaluator.build(
      @name,
      dynamic_options: nil,
      options: @options,
      selector: base_selector
    )
    DefineHasOnePredicateMethods.new(@name, evaluator_class: evaluator_class).run(target)
  end
end