Class: Highway::Steps::Registry
- Inherits:
-
Object
- Object
- Highway::Steps::Registry
- Defined in:
- lib/highway/steps/registry.rb
Overview
This class is responsible for keeping track of available steps.
Class Method Summary collapse
-
.new_and_load_default_library ⇒ Highway::Steps::Registry
Initialize an instance and automatically load all steps in the default library.
Instance Method Summary collapse
-
#get_by_name(step_name) ⇒ Class?
Get a step definition class by its name.
-
#initialize ⇒ Registry
constructor
Initialize an instance.
-
#register(step_class) ⇒ Void
Add a new step definition class to the registry.
-
#unregister(step_class) ⇒ Void
Remove a step definition class from the registry.
Constructor Details
#initialize ⇒ Registry
Initialize an instance.
17 18 19 |
# File 'lib/highway/steps/registry.rb', line 17 def initialize() @classes = Set.new() end |
Class Method Details
.new_and_load_default_library ⇒ Highway::Steps::Registry
Initialize an instance and automatically load all steps in the default library.
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.('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.
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.
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.
70 71 72 |
# File 'lib/highway/steps/registry.rb', line 70 def unregister(step_class) @classes.remove(step_class) end |