Sha256: f1cc163145bd9a5ebafa17392c117d0d3de976151273e5558b79d8f44dbebe21

Contents?: true

Size: 872 Bytes

Versions: 17

Compression:

Stored size: 872 Bytes

Contents

module FactoryBot
  class DefinitionHierarchy
    delegate :callbacks, :constructor, :to_create, to: Internal

    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

17 entries across 17 versions & 2 rubygems

Version Path
factory_bot-6.5.0 lib/factory_bot/definition_hierarchy.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/factory_bot-6.4.6/lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.6 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.5 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.4 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.3 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.2 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.1 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.4.0 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.3.0 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.2.1 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.2.0 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.1.0 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.0.2 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.0.1 lib/factory_bot/definition_hierarchy.rb
factory_bot-6.0.0 lib/factory_bot/definition_hierarchy.rb
factory_bot-5.2.0 lib/factory_bot/definition_hierarchy.rb