module Watir::AttributeHelper

@private

Extended by Element, provides methods for defining attributes on the element classes.

Private Class Methods

extended(klass) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 47
def self.extended(klass)
  klass.class_eval do
    # undefine deprecated methods to use them for Element attributes
    [:id, :type].each { |m| undef_method m if method_defined? m }
  end
end

Public Instance Methods

attribute(type, method, attr) click to toggle source

YARD macro to generated friendly documentation for attributes.

@macro [attach] attribute

@method $2
@return [$1] value of $3 property
# File lib/watir-webdriver/attribute_helper.rb, line 40
def attribute(type, method, attr)
  typed_attributes[type] << [method, attr]
  define_attribute(type, method, attr)
end
attribute_list() click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 21
def attribute_list
  @attribute_list ||= (
    list = typed_attributes.values.flatten
    list += ancestors[1..-1].map do |e|
      e.attribute_list if e.respond_to?(:attribute_list)
    end.compact.flatten
  ).uniq
end
Also aliased as: attributes
attributes()
Alias for: attribute_list
inherit_attributes_from(kls) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 11
def inherit_attributes_from(kls)
  kls.typed_attributes.each do |type, attrs|
    attrs.each { |method, attr| attribute type, method, attr }
  end
end
typed_attributes() click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 17
def typed_attributes
  @typed_attributes ||= Hash.new { |hash, type| hash[type] = []  }
end

Private Instance Methods

define_attribute(type, name, attr) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 54
def define_attribute(type, name, attr)
  case type.to_s
  when 'String'
    define_string_attribute(name, attr)
  when 'Boolean'
    define_boolean_attribute(name, attr)
  when 'Fixnum'
    define_int_attribute(name, attr)
  when 'Float'
    define_float_attribute(name, attr)
  else
    # $stderr.puts "treating #{type.inspect} as string for now"
  end
end
define_boolean_attribute(mname, aname) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 75
def define_boolean_attribute(mname, aname)
  define_method mname do
    attribute_value(aname) == "true"
  end
end
define_float_attribute(mname, aname) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 88
def define_float_attribute(mname, aname)
  define_method mname do
    value = attribute_value(aname)
    value && Float(value)
  end
end
define_int_attribute(mname, aname) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 81
def define_int_attribute(mname, aname)
  define_method mname do
    value = attribute_value(aname)
    value && Integer(value)
  end
end
define_string_attribute(mname, aname) click to toggle source
# File lib/watir-webdriver/attribute_helper.rb, line 69
def define_string_attribute(mname, aname)
  define_method mname do
    attribute_value(aname).to_s
  end
end