Sha256: fac1d1d108633e16021cf13d4e66aaa8746af43b246e9c30b8cdf13932857294

Contents?: true

Size: 725 Bytes

Versions: 1

Compression:

Stored size: 725 Bytes

Contents

module Helpers
  def assoc_name(*args)
    ROM::Relation::Name[*args]
  end

  def define_schema(name, attrs = [])
    relation_name = ROM::Relation::Name.new(name)
    ROM::SQL::Schema.define(
      relation_name,
      attributes: attrs.map { |key, value| value.meta(name: key, source: relation_name) },
      attr_class: ROM::SQL::Attribute
    )
  end

  def define_type(name, id, **opts)
    ROM::SQL::Attribute.new(ROM::Types.const_get(id).meta(name: name, **opts))
  end

  def build_assoc(type, *args)
    klass = Dry::Core::Inflector.classify(type)
    definition = ROM::Associations::Definitions.const_get(klass).new(*args)
    ROM::SQL::Associations.const_get(definition.type).new(definition, relations)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-sql-2.0.0.beta1 spec/support/helpers.rb