Sha256: e7c11d27003b094c6f421a85e88ecb348bc6d8489df29ff253c32b66c801aabf

Contents?: true

Size: 1.68 KB

Versions: 93

Compression:

Stored size: 1.68 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 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, *args, &block)
          FactoryGirl.register_sequence(Sequence.new(name, *args, &block))
        end

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

        def to_create(&block)
          FactoryGirl.to_create(&block)
        end

        def skip_create
          FactoryGirl.skip_create
        end

        def initialize_with(&block)
          FactoryGirl.initialize_with(&block)
        end

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

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

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

  extend Syntax::Default
end

Version data entries

93 entries across 83 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/syntax/default.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb
challah-0.9.1.beta.3 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb
factory_girl-4.2.0 lib/factory_girl/syntax/default.rb
challah-0.9.1.beta vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb
challah-0.9.0 vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/default.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/syntax/default.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.0.0/lib/factory_girl/syntax/default.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb