Class: ROM::LDAP::Schema

Inherits:
Schema
  • Object
show all
Defined in:
lib/rom/ldap/schema.rb,
lib/rom/ldap/schema/dsl.rb,
lib/rom/ldap/schema/inferrer.rb,
lib/rom/ldap/schema/type_builder.rb,
lib/rom/ldap/schema/attributes_inferrer.rb

Defined Under Namespace

Classes: AttributesInferrer, DSL, Inferrer, TypeBuilder

Instance Method Summary collapse

Instance Method Details

#call(relation) ⇒ Relation

Create a new relation based on the schema definition

Parameters:

  • relation (Relation)

    The source relation

Returns:



31
32
33
34
# 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

#emptySchema

Return an empty schema

Returns:



106
107
108
# File 'lib/rom/ldap/schema.rb', line 106

def empty
  new(EMPTY_ARRAY)
end

#finalize_associations!(relations:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



111
112
113
114
115
116
117
# 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) ⇒ Schema

Join with another schema

Parameters:

  • other (Schema)

    The other schema to join with

Returns:



88
89
90
# File 'lib/rom/ldap/schema.rb', line 88

def join(other)
  merge(other.joined)
end

#joinedSchema

Return a new schema with all attributes marked as joined

Returns:



97
98
99
# File 'lib/rom/ldap/schema.rb', line 97

def joined
  new(map(&:joined))
end

#project(*names, &block) ⇒ Schema

Project a schema

Returns:

  • (Schema)

    A new schema with projected attributes

See Also:



55
56
57
58
59
60
61
# 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) ⇒ Schema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Project schema so that it only contains renamed foreign key

Returns:



77
78
79
# File 'lib/rom/ldap/schema.rb', line 77

def project_fk(mapping)
  new(rename(mapping).map(&:foreign_key))
end

#project_pkSchema

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Project schema so that it only contains primary key

Returns:



68
69
70
# File 'lib/rom/ldap/schema.rb', line 68

def project_pk
  project(*primary_key_names)
end

#rename(mapping) ⇒ Schema

Rename schema attributes

Returns:

  • (Schema)

    A new schema with renamed attributes

See Also:



43
44
45
# 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) ⇒ Mixed

Open restriction DSL for defining query conditions using schema attributes

Returns:

  • (Mixed)

    Result of the block call

See Also:



20
21
22
# File 'lib/rom/ldap/schema.rb', line 20

def restriction(&block)
  RestrictionDSL.new(self).call(&block)
end