Sha256: ae1a1a4151f83396be2e059d60a7d2b86bff75470c2e1183d988bb8484dc727b

Contents?: true

Size: 1010 Bytes

Versions: 9

Compression:

Stored size: 1010 Bytes

Contents

module FactoryGirl
  module Syntax
    module Default
      include Methods

      def define(&block)
        DSL.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)
          proxy.instance_eval(&block) if block_given?
          if parent = options.delete(:parent)
            factory.inherit_from(FactoryGirl.factory_by_name(parent))
          end
          FactoryGirl.register_factory(factory)

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

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

  extend Syntax::Default
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
factory_girl-2.0.3 lib/factory_girl/syntax/default.rb
factory_girl-2.0.2 lib/factory_girl/syntax/default.rb
factory_girl-2.0.1 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.rc4 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.rc3 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.rc2 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.rc1 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.beta5 lib/factory_girl/syntax/default.rb
factory_girl-2.0.0.beta4 lib/factory_girl/syntax/default.rb