lib/pry-factorybot.rb in pry-factorybot-0.1.1 vs lib/pry-factorybot.rb in pry-factorybot-0.1.2

- old
+ new

@@ -1,34 +1,20 @@ require 'pry' -require 'pry-factorybot' +require 'factory_bot' module PryFactoryBot # TODO FactoryBot::Internal::DEFAULT_STRATEGIESでとれるようになるかも? - DEFAULT_STRATEGIES_NAMES = [:build, :create, :attributes_for, :build_stubbed, :null ] + DEFAULT_STRATEGIES_NAMES = [:build, :create, :attributes_for, :build_stubbed, :null].freeze - DEFAULT_STRATEGIES_NAMES.each do |strategy_name| - class_eval <<-EOS - class FactoryBot#{strategy_name.capitalize}Command < ::Pry::ClassCommand - match "#{strategy_name}" - group "FactorBot" - - description "FactorBot.#{strategy_name}" - - banner <<-BANNER - Usage: #{strategy_name} - FactorBot.create. - BANNER - - def process(name, *traits_and_overrides, &block) - ::FactoryBot.#{strategy_name}(name, *traits_and_overrides, &block) - rescue => e - puts e.message - end + Commands = Pry::CommandSet.new do + DEFAULT_STRATEGIES_NAMES.each do |strategy| + command "#{strategy}", "FactoryBot.#{strategy}" do + FactoryBot.class_eval <<-EOS + #{Readline::HISTORY.to_a.last} + EOS end - EOS + end end - - DEFAULT_STRATEGIES_NAMES.each do |strategy_name| - eval "Pry::Commands.add_command(PryFactoryBot::FactoryBot#{strategy_name.capitalize}Command)" - end end + +Pry.config.commands.import PryFactoryBot::Commands