Sha256: 8d8cd7df0efe49f38581597d9c83537106a93a0795ec5eab73d95cd3117b3905

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

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
      define_pair_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, &block|
        amount.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
      end
    end

    def define_pair_strategy_method
      strategy_name = @strategy_name

      define_syntax_method("#{strategy_name}_pair") do |name, *traits_and_overrides, &block|
        2.times.map { send(strategy_name, name, *traits_and_overrides, &block) }
      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

12 entries across 9 versions & 5 rubygems

Version Path
opal-factory_girl-4.5.0.3 factory_girl/lib/factory_girl/strategy_syntax_method_registrar.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/strategy_syntax_method_registrar.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/lib/factory_girl/strategy_syntax_method_registrar.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/factory_girl-4.4.0/lib/factory_girl/strategy_syntax_method_registrar.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/factory_girl-4.4.0/lib/factory_girl/strategy_syntax_method_registrar.rb
factory_girl-4.5.0 lib/factory_girl/strategy_syntax_method_registrar.rb
factory_girl-4.4.0 lib/factory_girl/strategy_syntax_method_registrar.rb
factory_girl-4.3.0 lib/factory_girl/strategy_syntax_method_registrar.rb