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



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

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

    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