Module: Hypercuke::StepAdapters
- Extended by:
- StepAdapters
- Included in:
- StepAdapters
- Defined in:
- lib/hypercuke/step_adapters.rb,
lib/hypercuke/step_adapters.rb,
lib/hypercuke/step_adapters.rb,
lib/hypercuke/step_adapters.rb
Overview
One final bit of business before we go: when testing code that defines classes and binds them to constants, it is occasionally useful to reset to a blank slate.
Instance Method Summary collapse
- #clear ⇒ Object
-
#define(topic_name, layer_name) ⇒ Object
Here’s the entry point for the adapter definition API.
- #define_topic_module(topic_name) ⇒ Object
-
#fetch_topic_module(topic_name) ⇒ Object
We’ll get to what makes a topic module special is in a moment, but here’s how we fetch one:.
Instance Method Details
#clear ⇒ Object
120 121 122 123 124 |
# File 'lib/hypercuke/step_adapters.rb', line 120 def clear constants.each do |c| remove_const c end end |
#define(topic_name, layer_name) ⇒ Object
Here’s the entry point for the adapter definition API. It’s entirely possible that a user might want to define their step adapters in a re-entrant way (much like we’ve been reopening the same modules and classes in this file), so this bit of the code will either create a new step adapter, or return one that’s already been defined.
88 89 90 91 |
# File 'lib/hypercuke/step_adapters.rb', line 88 def define(topic_name, layer_name) topic_module = define_topic_module(topic_name) step_adapter = topic_module.define_step_adapter( layer_name ) end |
#define_topic_module(topic_name) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/hypercuke/step_adapters.rb', line 99 def define_topic_module(topic_name) fetch_topic_module(topic_name) rescue Hypercuke::TopicNotDefinedError const_name = MiniInflector.camelize(topic_name) const_set const_name, TopicModule.new end |
#fetch_topic_module(topic_name) ⇒ Object
We’ll get to what makes a topic module special is in a moment, but here’s how we fetch one:
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hypercuke/step_adapters.rb', line 32 def fetch_topic_module(topic_name) # FIXME: cyclomatic complexity Hypercuke.topics.validate(topic_name) do fail TopicNotDefinedError, "Topic not defined: #{topic_name}" end validate_topic_module \ begin const_get( MiniInflector.camelize(topic_name) ) rescue NameError => e raise Hypercuke::TopicNotDefinedError.wrap(e) end end |