Sha256: f1767b14001698ac41f27dd8915de35060897e63301fab37ebd3a5eb19491847

Contents?: true

Size: 1.45 KB

Versions: 28

Compression:

Stored size: 1.45 KB

Contents

module FactoryGirl
  module Syntax
    module Default
      include Methods

      def define(&block)
        DSL.run(block)
      end

      def modify(&block)
        ModifyDSL.run(block)
      end

      class DSL
        def self.run(block)
          new.instance_eval(&block)
        end

        def factory(name, options = {}, &block)
          factory = Factory.new(name, options)
          proxy = FactoryGirl::DefinitionProxy.new(factory.definition)
          proxy.instance_eval(&block) if block_given?

          FactoryGirl.register_factory(factory)

          proxy.child_factories.each do |(child_name, child_options, child_block)|
            parent_factory = child_options.delete(:parent) || name
            factory(child_name, child_options.merge(:parent => parent_factory), &child_block)
          end
        end

        def sequence(name, start_value = 1, &block)
          FactoryGirl.register_sequence(Sequence.new(name, start_value, &block))
        end

        def trait(name, &block)
          FactoryGirl.register_trait(Trait.new(name, &block))
        end
      end

      class ModifyDSL
        def self.run(block)
          new.instance_eval(&block)
        end

        def factory(name, options = {}, &block)
          factory = FactoryGirl.factory_by_name(name)
          proxy = FactoryGirl::DefinitionProxy.new(factory.definition.overridable)
          proxy.instance_eval(&block)
        end
      end
    end
  end

  extend Syntax::Default
end

Version data entries

28 entries across 23 versions & 3 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/factory_girl-2.6.4/lib/factory_girl/syntax/default.rb
challah-0.6.2 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
factory_girl-2.6.4 lib/factory_girl/syntax/default.rb
factory_girl-2.6.3 lib/factory_girl/syntax/default.rb
factory_girl-2.6.2 lib/factory_girl/syntax/default.rb
challah-0.5.1 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/default.rb
factory_girl-2.6.1 lib/factory_girl/syntax/default.rb
challah-0.5.0 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/default.rb
factory_girl-2.6.0 lib/factory_girl/syntax/default.rb
factory_girl-2.5.2 lib/factory_girl/syntax/default.rb