class Highway::Steps::Registry

This class is responsible for keeping track of available steps.

Public Class Methods

new() click to toggle source

Initialize an instance.

# File lib/highway/steps/registry.rb, line 17
def initialize()
  @classes = Set.new()
end
new_and_load_default_library() click to toggle source

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

@return [Highway::Steps::Registry]

# 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

Private Class Methods

step_class_valid?(step_class) click to toggle source
# File lib/highway/steps/registry.rb, line 85
def self.step_class_valid?(step_class)
  step_class.is_a?(Class) && step_class < Highway::Steps::Step
end

Public Instance Methods

get_by_name(step_name) click to toggle source

Get a step definition class by its name.

@param step_name [String] The step name.

@return [Class, nil]

# 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) click to toggle source

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

@param step_class [Class] The step definition class.

@raise [ArgumentError] If trying to register an invalid step class.

@return [Void]

# 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) click to toggle source

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

@param step_class [Class] The step definition class.

@return [Void]

# File lib/highway/steps/registry.rb, line 70
def unregister(step_class)
  @classes.remove(step_class)
end