File: implicit.rb

package info (click to toggle)
ruby-factory-bot 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: ruby: 7,827; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module FactoryBot
  class Declaration
    # @api private
    class Implicit < Declaration
      def initialize(name, factory = nil, ignored = false)
        super(name, ignored)
        @factory = factory
      end

      def ==(other)
        self.class == other.class &&
          name == other.name &&
          factory == other.factory &&
          ignored == other.ignored
      end

      protected

      attr_reader :factory

      private

      def build
        if FactoryBot.factories.registered?(name)
          [Attribute::Association.new(name, name, {})]
        elsif FactoryBot::Internal.sequences.registered?(name)
          [Attribute::Sequence.new(name, name, @ignored)]
        elsif @factory.name.to_s == name.to_s
          message = "Self-referencing trait '#{@name}'"
          raise TraitDefinitionError, message
        else
          @factory.inherit_traits([name])
          []
        end
      end
    end
  end
end