Sha256: e019480a207ac7d74a7ab9922705c59a7be6528aca214c1843caf3594c2089e5

Contents?: true

Size: 736 Bytes

Versions: 3

Compression:

Stored size: 736 Bytes

Contents

require 'rom/sql/type'
require 'rom/sql/schema/inferrer'
require 'rom/sql/schema/associations_dsl'

module ROM
  module SQL
    class Schema < ROM::Schema
      class DSL < ROM::Schema::DSL
        attr_reader :associations_dsl

        def associations(&block)
          @associations_dsl = AssociationsDSL.new(relation, &block)
        end

        def call
          SQL::Schema.define(
            relation, opts.merge(attributes: attributes.values, type_class: SQL::Type)
          )
        end

        def opts
          opts = { inferrer: inferrer }

          if associations_dsl
            { **opts, associations: associations_dsl.call }
          else
            opts
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-1.0.0.beta3 lib/rom/sql/schema/dsl.rb
rom-sql-1.0.0.beta2 lib/rom/sql/schema/dsl.rb
rom-sql-1.0.0.beta1 lib/rom/sql/schema/dsl.rb