Module: AR::UUID::TableDefinition

Defined in:
lib/ar/uuid/table_definition.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ar/uuid/table_definition.rb', line 6

def self.included(base)
  base.class_eval do
    def references(*args, **options)
      super(*args, **options, type: options.fetch(:type, :text))
    end

    def belongs_to(*, **)
      references(*, **)
    end
  end
end

Instance Method Details

#primary_key(name, type = :primary_key, **options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ar/uuid/table_definition.rb', line 18

def primary_key(name, type = :primary_key, **options)
  prefix = options.delete(:prefix) || @name

  options[:default] ||= proc do
    ::AR::UUID.default_function_with_prefix(prefix)
  end

  type = :text if type == :primary_key

  super
end