Sha256: c3727da7101d6c39fd546ae6df7e67f981a36d3adc1fdcd76fa83044c8145035

Contents?: true

Size: 663 Bytes

Versions: 2

Compression:

Stored size: 663 Bytes

Contents

module FactoryGirl
  class Callback
    VALID_NAMES = [:after_build, :after_create, :after_stub].freeze

    attr_reader :name, :block

    def initialize(name, block)
      @name  = name.to_sym
      @block = block
      check_name
    end

    def run(instance, proxy)
      case block.arity
      when 1 then block.call(instance)
      when 2 then block.call(instance, proxy)
      else block.call
      end
    end

    private

    def check_name
      unless VALID_NAMES.include?(name)
        raise InvalidCallbackNameError, "#{name} is not a valid callback name. " +
          "Valid callback names are #{VALID_NAMES.inspect}"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factory_girl-2.2.0 lib/factory_girl/callback.rb
factory_girl-2.1.2 lib/factory_girl/callback.rb