class ActiveCucumber::Cucumberator

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.

Public Class Methods

new(object, context) click to toggle source

object - the instance to decorate

# 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

Public Instance Methods

value_for(key) click to toggle source

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.

# 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

Private Instance Methods

method_missing(method_name) click to toggle source
# 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
normalized_key(key) click to toggle source

Converts the key given in Cucumber format into the format used to access attributes on an ActiveRecord instance.

# File lib/active_cucumber/cucumberator.rb, line 45
def normalized_key key
  key.to_s.downcase.parameterize.underscore
end
value_method_name(key) click to toggle source

Returns the name of the value_of_* method for the given key

# File lib/active_cucumber/cucumberator.rb, line 51
def value_method_name key
  "value_for_#{normalized_key key}"
end