class ActiveCucumber::Creator
Creates ActiveRecord entries with data from given Cucumber tables.
Public Class Methods
new(attributes, context)
click to toggle source
# File lib/active_cucumber/creator.rb, line 10 def initialize attributes, context @attributes = attributes context.each do |key, value| instance_variable_set "@#{key}", value end end
Public Instance Methods
factorygirl_attributes()
click to toggle source
Returns the FactoryGirl version of this Creator’s attributes
# File lib/active_cucumber/creator.rb, line 18 def factorygirl_attributes symbolize_attributes! @attributes.each do |key, value| next unless respond_to?(method = method_name(key)) if (result = send method, value) || value.nil? @attributes[key] = result if @attributes.key? key else @attributes.delete key end end end
Private Instance Methods
method_missing(method_name, *arguments)
click to toggle source
# File lib/active_cucumber/creator.rb, line 33 def method_missing method_name, *arguments # This is necessary so that a Creator subclass can access # methods of @attributes as if they were its own. @attributes.send method_name, *arguments end
method_name(key)
click to toggle source
Returns the name of the value_for method for the given key
# File lib/active_cucumber/creator.rb, line 41 def method_name key "value_for_#{key}" end
normalized_key(key)
click to toggle source
Converts the key given in Cucumber format into FactoryGirl format
# File lib/active_cucumber/creator.rb, line 47 def normalized_key key key.downcase.parameterize.underscore.to_sym end
normalized_value(value)
click to toggle source
# File lib/active_cucumber/creator.rb, line 51 def normalized_value value value.blank? ? nil : value end
symbolize_attributes!()
click to toggle source
Makes the keys on @attributes be normalized symbols
# File lib/active_cucumber/creator.rb, line 57 def symbolize_attributes! @attributes = {}.tap do |result| @attributes.each do |key, value| result[normalized_key key] = normalized_value value end end end