Sha256: 94c77a08311581df0b4148f1527db231237af7b940812fb35cdc3833fe912c89

Contents?: true

Size: 958 Bytes

Versions: 5

Compression:

Stored size: 958 Bytes

Contents

module FactoryGirl
  class DefinitionHierarchy
    def callbacks
      []
    end

    def constructor
      FactoryGirl.constructor
    end

    def to_create
      FactoryGirl.to_create
    end

    def self.build_from_definition(definition)
      build_to_create(&definition.to_create)
      build_constructor(&definition.constructor)
      add_callbacks definition.callbacks
    end

    def self.add_callbacks(callbacks)
      if callbacks.any?
        define_method :callbacks do
          super() + callbacks
        end
      end
    end
    private_class_method :add_callbacks

    def self.build_constructor(&block)
      if block
        define_method(:constructor) do
          block
        end
      end
    end
    private_class_method :build_constructor

    def self.build_to_create(&block)
      if block
        define_method(:to_create) do
          block
        end
      end
    end
    private_class_method :build_to_create
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
challah-1.0.0 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/definition_hierarchy.rb
challah-1.0.0.beta3 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/definition_hierarchy.rb
challah-1.0.0.beta2 vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/definition_hierarchy.rb
challah-1.0.0.beta vendor/bundle/gems/factory_girl-4.2.0/lib/factory_girl/definition_hierarchy.rb
factory_girl-4.2.0 lib/factory_girl/definition_hierarchy.rb