Module: AX

Defined in:
lib/accessibility/factory.rb

Overview

Namespace container for all the accessibility objects.

Defined Under Namespace

Classes: Application, Button, Element, Menu, PopUpButton, RadioButton, Row, ScrollArea, StaticText, SystemWide, TextArea, TextField

Constant Summary

MUTEX =

Mutex to make sure we only create one class at a time.

Returns:

  • (Mutex)
Mutex.new
AX::PopUpButton
DOCK =
Deprecated.

Please use Application.dock instead

The Mac OS X dock application.

Returns:

AX::Application.dock

Class Method Summary collapse

Class Method Details

.class_for(role) ⇒ Class

Find the class for a given role

If the class does not exist it will be created.

Parameters:

  • role (#to_s)

Returns:

  • (Class)


28
29
30
31
32
33
34
# File 'lib/accessibility/factory.rb', line 28

def class_for role
  if AX.const_defined? role, false
    AX.const_get role
  else
    create_class role
  end
end

.class_for2(subrole, role) ⇒ Class

Find the class for a given subrole and role

If the class does not exist it will be created on demand.

Parameters:

  • subrole (#to_s)
  • role (#to_s)

Returns:

  • (Class)


46
47
48
49
50
51
52
# File 'lib/accessibility/factory.rb', line 46

def class_for2 subrole, role
  if AX.const_defined? subrole, false
    AX.const_get subrole
  else
    create_class2 subrole, role
  end
end

.create_class(name) ⇒ Class

Create a class in the AX namespace that has Element as the superclass

Parameters:

  • name (#to_s)

Returns:

  • (Class)


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/accessibility/factory.rb', line 62

def create_class name
  MUTEX.synchronize do
    # re-check now that we are in the critical section
    @klass = if AX.const_defined? name, false
               AX.const_get name
             else
               klass = Class.new AX::Element
               AX.const_set name, klass
             end
  end
  @klass
end

.create_class2(name, superklass) ⇒ Class

Create a new class in the AX namesapce that has the given superklass as the superclass

Parameters:

  • name (#to_s)
  • superklass (#to_s)

Returns:

  • (Class)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/accessibility/factory.rb', line 84

def create_class2 name, superklass
  unless AX.const_defined? superklass, false
    create_class superklass
  end
  MUTEX.synchronize do
    # re-check now that we are in the critical section
    @klass = if AX.const_defined? name, false
               AX.const_get name
             else
               klass = Class.new AX.const_get(superklass)
               AX.const_set name, klass
             end
  end
  @klass
end