Sha256: 75e1c3dd94d1cfad575a663bfa8d7fd917d348fa944ce1397ee49c2bd1e887c1

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module PageEz
  module MethodGenerators
    class HasOneComposedClass
      attr_reader :selector

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

      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
    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/has_one_composed_class.rb
page_ez-0.1.0 lib/page_ez/method_generators/has_one_composed_class.rb