<commit_before>require 'page-object/elements'
require 'page-object/platforms/selenium_webdriver/page_object'
require 'page-object/platforms/watir_webdriver/page_object'

module PageObject
  module Widgets

    #
    # Module that allows for the registration of widget classes which extend the functionality of PageObject
    # Allows any classes which extend PageObject::Element to be used as PageObject elements.
    # This allows such widgets to be created using the defined tags.
    #
    # @param [Symbol] defines the symbol which will be used as an accessor name.
    # @param [Class] the widget class extending PageObject::Elements::Element
    # @param [Symbol] the symbol of the html element used when searching for this widget.
    #
    #
    def self.register_widget(widget_tag, widget_class, base_element_tag)
      if widget_class.ancestors.include? Elements::Element
        define_accessors(Accessors, widget_tag, widget_class)
        define_nested_elements(Elements::Element, widget_tag)
        define_locators(PageObject, widget_tag)
        define_selenium_accessors(Platforms::SeleniumWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
        define_watir_accessors(Platforms::WatirWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
      end
    end

    private

    def self.define_accessors(base, widget_tag, widget_class)
      accessors_module = Module.new do
        define_method widget_tag do |name, identifier={}, &block|
          identifier = {:index => 0} if identifier.empty?
          define_method("#{name}_element") do
            return call_block(&block) if block
            platform.send("#{widget_tag}_for", identifier.clone)
          end
          define_method("#{name}?") do
            return call_block(&block).exists? if block
            platform.send("#{widget_tag}_for", identifier.clone).exists?
          end
          if widget_class.respond_to? :accessor_methods
            widget_class.accessor_methods(self, name)
          end
        end
      end

      base.send(:include, accessors_module)
    end

    def self.define_watir_accessors(base, widget_tag, widget_class, base_element_tag)
      define_singular_watir_accessor(base, base_element_tag, widget_class, widget_tag)
      define_multiple_watir_accessor(base, base_element_tag, widget_class, widget_tag)
    end
<commit_msg>making change that will not work in 1.8.7<commit_after>require 'page-object/elements'
require 'page-object/platforms/selenium_webdriver/page_object'
require 'page-object/platforms/watir_webdriver/page_object'

module PageObject
  module Widgets

    #
    # Module that allows for the registration of widget classes which extend the functionality of PageObject
    # Allows any classes which extend PageObject::Element to be used as PageObject elements.
    # This allows such widgets to be created using the defined tags.
    #
    # @param [Symbol] defines the symbol which will be used as an accessor name.
    # @param [Class] the widget class extending PageObject::Elements::Element
    # @param [Symbol] the symbol of the html element used when searching for this widget.
    #
    #
    def self.register_widget(widget_tag, widget_class, base_element_tag)
      if widget_class.ancestors.include? Elements::Element
        define_accessors(Accessors, widget_tag, widget_class)
        define_nested_elements(Elements::Element, widget_tag)
        define_locators(PageObject, widget_tag)
        define_selenium_accessors(Platforms::SeleniumWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
        define_watir_accessors(Platforms::WatirWebDriver::PageObject, widget_tag, widget_class, base_element_tag)
      end
    end

    private

    def self.define_accessors(base, widget_tag, widget_class)
      accessors_module = Module.new do
        define_method widget_tag do |name, identifier={:index => 0}, &block|
          define_method("#{name}_element") do
            return call_block(&block) if block
            platform.send("#{widget_tag}_for", identifier.clone)
          end
          define_method("#{name}?") do
            return call_block(&block).exists? if block
            platform.send("#{widget_tag}_for", identifier.clone).exists?
          end
          if widget_class.respond_to? :accessor_methods
            widget_class.accessor_methods(self, name)
          end
        end
      end

      base.send(:include, accessors_module)
    end

    def self.define_watir_accessors(base, widget_tag, widget_class, base_element_tag)
      define_singular_watir_accessor(base, base_element_tag, widget_class, widget_tag)
      define_multiple_watir_accessor(base, base_element_tag, widget_class, widget_tag)
    end

{'fraction_non_alphanumeric': 0.07705298712265146, 'fraction_numerical': 0.0010555203715431707, 'mean_word_length': 3.626953125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5599407', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1321, 'n_words': 339}