Class: ActiveCucumber::Cucumberator
- Inherits:
-
Object
- Object
- ActiveCucumber::Cucumberator
- Defined in:
- lib/active_cucumber/cucumberator.rb
Overview
A decorator for ActiveRecord objects that adds methods to format record attributes as they are displayed in Cucumber tables.
This class is used by default. You can subclass it to create custom Cucumberators for your ActiveRecord classes.
Instance Method Summary collapse
-
#initialize(object, context) ⇒ Cucumberator
constructor
object - the instance to decorate.
-
#value_for(key) ⇒ Object
Returns the Cucumber value for the given attribute key.
Constructor Details
#initialize(object, context) ⇒ Cucumberator
object - the instance to decorate
11 12 13 14 15 16 |
# File 'lib/active_cucumber/cucumberator.rb', line 11 def initialize object, context @object = object context.each do |key, value| instance_variable_set "@#{key}", value end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object (private)
36 37 38 39 40 |
# File 'lib/active_cucumber/cucumberator.rb', line 36 def method_missing method_name # This is necessary so that a Cucumberator subclass can access # attributes of @object as if they were its own. @object.send method_name end |
Instance Method Details
#value_for(key) ⇒ Object
Returns the Cucumber value for the given attribute key.
If a value_for_* method is not defined for the given key, returns the attribute value of the decorated object, converted to a String.
24 25 26 27 28 29 30 31 |
# File 'lib/active_cucumber/cucumberator.rb', line 24 def value_for key method_name = value_method_name key if respond_to? method_name send(method_name).to_s else @object.send(normalized_key key).to_s end end |