Module: Torque::PostgreSQL::Attributes::Builder

Defined in:
lib/torque/postgresql/attributes/builder.rb,
lib/torque/postgresql/attributes/builder/enum.rb,
lib/torque/postgresql/attributes/builder/period.rb

Defined Under Namespace

Classes: Enum, Period

Class Method Summary collapse

Class Method Details

.include_on(klass, method_name, builder_klass, **extra, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/torque/postgresql/attributes/builder.rb', line 8

def self.include_on(klass, method_name, builder_klass, **extra, &block)
  klass.define_singleton_method(method_name) do |*args, **options|
    return unless connection.table_exists?(table_name)

    args.each do |attribute|
      begin
        # Generate methods on self class
        builder = builder_klass.new(self, attribute, extra.merge(options))
        builder.conflicting?
        builder.build

        # Additional settings for the builder
        instance_exec(builder, &block) if block.present?
      rescue Interrupt
        # Not able to build the attribute, maybe pending migrations
      end
    end
  end
end