Sha256: 350c54575e44a40d860190e05b51ea8645a4e5d8970b246a68a5812743a21d7e

Contents?: true

Size: 675 Bytes

Versions: 1

Compression:

Stored size: 675 Bytes

Contents

# frozen_string_literal: true

module AR
  module UUID
    module TableDefinition
      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar-sqlite-uuid-0.0.2 lib/ar/uuid/table_definition.rb