Class: ROM::LDAP::Schema
- Inherits:
-
Schema
- Object
- Schema
- ROM::LDAP::Schema
- 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
-
#call(relation) ⇒ Relation
Create a new relation based on the schema definition.
-
#empty ⇒ Schema
Return an empty schema.
- #finalize_associations!(relations:) ⇒ Object private
-
#join(other) ⇒ Schema
Join with another schema.
-
#joined ⇒ Schema
Return a new schema with all attributes marked as joined.
-
#project(*names, &block) ⇒ Schema
Project a schema.
-
#project_fk(mapping) ⇒ Schema
private
Project schema so that it only contains renamed foreign key.
-
#project_pk ⇒ Schema
private
Project schema so that it only contains primary key.
-
#rename(mapping) ⇒ Schema
Rename schema attributes.
-
#restriction(&block) ⇒ Mixed
Open restriction DSL for defining query conditions using schema attributes.
Instance Method Details
#call(relation) ⇒ Relation
Create a new relation based on the schema definition
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 |
#empty ⇒ Schema
Return an empty schema
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
88 89 90 |
# File 'lib/rom/ldap/schema.rb', line 88 def join(other) merge(other.joined) end |
#joined ⇒ Schema
Return a new schema with all attributes marked as joined
97 98 99 |
# File 'lib/rom/ldap/schema.rb', line 97 def joined new(map(&:joined)) end |
#project(*names, &block) ⇒ Schema
Project a schema
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
77 78 79 |
# File 'lib/rom/ldap/schema.rb', line 77 def project_fk(mapping) new(rename(mapping).map(&:foreign_key)) end |
#project_pk ⇒ 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 primary key
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
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
20 21 22 |
# File 'lib/rom/ldap/schema.rb', line 20 def restriction(&block) RestrictionDSL.new(self).call(&block) end |