Class: CapybaraObjects::RegistryInstance

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/capybara_objects/registry_instance.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistryInstance

Returns a new instance of RegistryInstance.



4
5
6
7
# File 'lib/capybara_objects/registry_instance.rb', line 4

def initialize
  self.ctypes = HashWithIndifferentAccess.new
  self.ptypes = HashWithIndifferentAccess.new
end

Instance Method Details

#lookup_ctype(ctype) ⇒ Class

Lookup a component object by its type

Parameters:

  • ctype (String)

    The component type to lookup

Returns:

  • (Class)

    The registered class

Raises:

  • ::CapybaraObjects::Exceptions::TypeNotRegistered



34
35
36
# File 'lib/capybara_objects/registry_instance.rb', line 34

def lookup_ctype(ctype)
  ctypes[ctype] or raise Exceptions::TypeNotRegistered.new(ctype)
end

#lookup_ptype(ptype) ⇒ Class

Lookup a page object by its type

Parameters:

  • ptype (String)

    The page object type to lookup

Returns:

  • (Class)

    The registered class

Raises:

  • ::CapybaraObjects::Exceptions::TypeNotRegistered



42
43
44
# File 'lib/capybara_objects/registry_instance.rb', line 42

def lookup_ptype(ptype)
  ptypes[ptype] or raise Exceptions::TypeNotRegistered.new(ptype)
end

#register_ctype(type, klass) ⇒ Object

Registers a component class so an alias can be used rather than worrying about the module path etc..

Parameters:

  • type (String)

    The type of component to register

  • klass (Class)

    The class to register



14
15
16
# File 'lib/capybara_objects/registry_instance.rb', line 14

def register_ctype(type, klass)
  ctypes[type] = klass
end

#register_ptype(type, klass) ⇒ Object

Registers a page object class so an alias can be used rather than worrying about the module path etc..

Parameters:

  • type (String)

    The type of page object to register

  • klass (Class)

    The class to register

Raises:

  • ::CapybaraObjects::Exceptions::UnregisteredType



26
27
28
# File 'lib/capybara_objects/registry_instance.rb', line 26

def register_ptype(type, klass)
  ptypes[type] = klass
end