Sha256: bdaa3f453a758c5bfa075d7b714143cebac23b31036191cc249cc386ee4da044

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

require 'domkey/view/page_object'
require 'domkey/view/page_object_collection'
require 'domkey/view/radio_group'
require 'domkey/view/checkbox_group'
require 'domkey/view/select_list'
require 'domkey/view/binder'

module Domkey

  module View

    module ClassMethods

      # PageObjectCollection factory
      def doms(key, &package)
        send :define_method, key do
          PageObjectCollection.new package, Proc.new { browser }
        end
      end

      # PageObject factory
      def dom(key, &package)
        send :define_method, key do
          PageObject.new package, Proc.new { browser }
        end
      end

      # build Binder with model and view
      # @return [Domkey::View::Binder]
      def binder model, browser: nil
        Binder.new model: model, view: self.new(browser)
      end

    end

    def self.included(klass)
      klass.extend(ClassMethods)
    end

    attr_accessor :browser

    # @param [Watir::Browser] (false)
    def initialize browser=nil
      @browser = browser
    end

    # browser for this view.
    # if View was initialized without a browser then default Domkey.browser is provided
    # @return [Watir::Browser]
    def browser
      @browser ||= Domkey.browser
    end

    def set value
      Binder.new(model: value, view: self).set
    end

    # @param [Hash{Symbol => Object}] view data where Symbol is semantic descriptor for a pageobject in the view
    # @param [Symbol] for one pageobject
    # @param [Array<Symbol>] for array of pageobjects
    #
    # @return [Hash{Symbol => Object}] data from the view
    def value value
      # transform value into hash
      value = case value
              when Symbol
                {value => nil}
              when Array
                #array of symbols
                Hash[value.map { |v| [v, nil] }]
              when Hash
                value
              end
      Binder.new(model: value, view: self).value
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
domkey-0.4.0 lib/domkey/view.rb
domkey-0.3.1 lib/domkey/view.rb