class ROM::LDAP::Schema

Public Instance Methods

call(relation) click to toggle source

Create a new relation based on the schema definition

@param relation [Relation] The source relation

@return [Relation]

@api public

# File lib/rom/ldap/schema.rb, line 31
def call(relation)
  dataset = relation.dataset.with(attrs: map(&:name), aliases: map(&:alias))
  relation.new(dataset, schema: self)
end
empty() click to toggle source

Return an empty schema

@return [Schema]

@api public

# File lib/rom/ldap/schema.rb, line 106
def empty
  new(EMPTY_ARRAY)
end
finalize_associations!(relations:) click to toggle source

@api private

Calls superclass method
# File lib/rom/ldap/schema.rb, line 111
def finalize_associations!(relations:)
  super do
    associations.map do |definition|
      LDAP::Associations.const_get(definition.type).new(definition, relations)
    end
  end
end
join(other) click to toggle source

Join with another schema

@param [Schema] other The other schema to join with

@return [Schema]

@api public

# File lib/rom/ldap/schema.rb, line 88
def join(other)
  merge(other.joined)
end
joined() click to toggle source

Return a new schema with all attributes marked as joined

@return [Schema]

@api public

# File lib/rom/ldap/schema.rb, line 97
def joined
  new(map(&:joined))
end
project(*names, &block) click to toggle source

Project a schema

@see ROM::Schema#project @see Relation#select

@return [Schema] A new schema with projected attributes

@api public

Calls superclass method
# File lib/rom/ldap/schema.rb, line 55
def project(*names, &block)
  if block
    super(*(names + ProjectionDSL.new(self).call(&block)))
  else
    super
  end
end
project_fk(mapping) click to toggle source

Project schema so that it only contains renamed foreign key

@return [Schema]

@api private

# File lib/rom/ldap/schema.rb, line 77
def project_fk(mapping)
  new(rename(mapping).map(&:foreign_key))
end
project_pk() click to toggle source

Project schema so that it only contains primary key

@return [Schema]

@api private

# File lib/rom/ldap/schema.rb, line 68
def project_pk
  project(*primary_key_names)
end
rename(mapping) click to toggle source

Rename schema attributes

@see Relation#rename

@return [Schema] A new schema with renamed attributes

@api public

Calls superclass method
# File lib/rom/ldap/schema.rb, line 43
def rename(mapping)
  super map(&:name).map { |k| { k => k } }.reduce(&:merge).merge(mapping)
end
restriction(&block) click to toggle source

Open restriction DSL for defining query conditions using schema attributes

@see Relation#where

@return [Mixed] Result of the block call

@api public

# File lib/rom/ldap/schema.rb, line 20
def restriction(&block)
  RestrictionDSL.new(self).call(&block)
end