Sha256: 0bd8b83c4714cd552ab3b427a80aa19d0c71620575e0db4756b0d9a2b07e2142

Contents?: true

Size: 962 Bytes

Versions: 88

Compression:

Stored size: 962 Bytes

Contents

module FactoryGirl
  # @api private
  class StrategySyntaxMethodRegistrar
    def initialize(strategy_name)
      @strategy_name = strategy_name
    end

    def define_strategy_methods
      define_singular_strategy_method
      define_list_strategy_method
    end

    private

    def define_singular_strategy_method
      strategy_name = @strategy_name

      define_syntax_method(strategy_name) do |name, *traits_and_overrides, &block|
        FactoryRunner.new(name, strategy_name, traits_and_overrides).run(&block)
      end
    end

    def define_list_strategy_method
      strategy_name = @strategy_name

      define_syntax_method("#{strategy_name}_list") do |name, amount, *traits_and_overrides|
        amount.times.map { send(strategy_name, name, *traits_and_overrides) }
      end
    end

    def define_syntax_method(name, &block)
      FactoryGirl::Syntax::Methods.module_exec do
        define_method(name, &block)
      end
    end
  end
end

Version data entries

88 entries across 79 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/strategy_syntax_method_registrar.rb
challah-0.8.3 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/strategy_syntax_method_registrar.rb