Class: Highway::Steps::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/highway/steps/registry.rb

Overview

This class is responsible for keeping track of available steps.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Initialize an instance.

[View source]

17
18
19
# File 'lib/highway/steps/registry.rb', line 17

def initialize()
  @classes = Set.new()
end

Class Method Details

.new_and_load_default_libraryHighway::Steps::Registry

Initialize an instance and automatically load all steps in the default library.

[View source]

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/highway/steps/registry.rb', line 25

def self.new_and_load_default_library()

  registry = self.new()

  Dir[File.expand_path('library/*.rb', File.dirname(__FILE__))].each do |file|
    require(file)
  end

  unless Highway::Steps.const_defined?("Library")
    return
  end

  Highway::Steps::Library.constants.each do |step_symbol|
    step_class = Highway::Steps::Library.const_get(step_symbol)
    if step_class_valid?(step_class)
      registry.register(step_class)
    end
  end

  registry

end

Instance Method Details

#get_by_name(step_name) ⇒ Class?

Get a step definition class by its name.

Parameters:

  • step_name (String)

    The step name.

Returns:

  • (Class, nil)
[View source]

79
80
81
# File 'lib/highway/steps/registry.rb', line 79

def get_by_name(step_name)
  @classes.find { |step_class| step_class.name == step_name }
end

#register(step_class) ⇒ Void

Add a new step definition class to the registry. Is it is already registered, this does nothing.

Parameters:

  • step_class (Class)

    The step definition class.

Returns:

  • (Void)

Raises:

  • (ArgumentError)

    If trying to register an invalid step class.

[View source]

56
57
58
59
60
61
62
# File 'lib/highway/steps/registry.rb', line 56

def register(step_class)
  if self.class.step_class_valid?(step_class)
    @classes.add(step_class)
  else
    raise ArgumentError.new("Step class `#{step_class}` is invalid.")
  end
end

#unregister(step_class) ⇒ Void

Remove a step definition class from the registry. If it is not registered, this does nothing.

Parameters:

  • step_class (Class)

    The step definition class.

Returns:

  • (Void)
[View source]

70
71
72
# File 'lib/highway/steps/registry.rb', line 70

def unregister(step_class)
  @classes.remove(step_class)
end