mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
89d5e944d5
This changes Strategy from a class to a module and removes inheritance. It introduces an Evaluation facade to make building strategies easier
29 lines
572 B
Ruby
29 lines
572 B
Ruby
module FactoryGirl
|
|
class StrategyCalculator
|
|
def initialize(name_or_object)
|
|
@name_or_object = name_or_object
|
|
end
|
|
|
|
def strategy
|
|
if strategy_is_object?
|
|
@name_or_object
|
|
else
|
|
strategy_name_to_object
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def strategy_is_object?
|
|
@name_or_object.is_a?(Class)
|
|
end
|
|
|
|
def strategy_name_to_object
|
|
case @name_or_object
|
|
when :build then Strategy::Build
|
|
when :create then Strategy::Create
|
|
else raise "unrecognized method #{@name_or_object}"
|
|
end
|
|
end
|
|
end
|
|
end
|