Sha256: ce2dcd6ec1ced1a13604eb3b05e9b8218e9fc159aead826780bf8bc6e37f723c

Contents?: true

Size: 901 Bytes

Versions: 60

Compression:

Stored size: 901 Bytes

Contents

module FactoryGirl
  class Callback
    attr_reader :name

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

    def run(instance, evaluator)
      case block.arity
      when 1 then syntax_runner.instance_exec(instance, &block)
      when 2 then syntax_runner.instance_exec(instance, evaluator, &block)
      else        syntax_runner.instance_exec(&block)
      end
    end

    def ==(other)
      name == other.name &&
        block == other.block
    end

    protected
    attr_reader :block

    private

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

    def syntax_runner
      @syntax_runner ||= SyntaxRunner.new
    end
  end
end

Version data entries

60 entries across 59 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.6 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.6.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.5.17 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.5.16 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.5.15 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb
classiccms-0.5.14 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/callback.rb