Class: Hanami::Model::Sql::Entity::Schema Private

Inherits:
Entity::Schema show all
Defined in:
lib/hanami/model/sql/entity/schema.rb

Overview

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

SQL Entity schema

This schema setup is automatic.

Hanami looks at the database columns, associations and potentially to the mapping in the repository (optional, only for legacy databases).

See Also:

Since:

  • 0.7.0

Instance Method Summary collapse

Constructor Details

#initialize(registry, relation, mapping) ⇒ Hanami::Model::Sql::Entity::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.

Build a new instance of Schema according to database columns, associations and potentially to mapping defined by the repository.

Parameters:

  • registry (Hash)

    a registry that keeps reference between entities class and their underscored names

  • relation (ROM::Relation)

    the database relation

  • mapping (Hanami::Model::Mapping)

    the optional repository mapping

Since:

  • 0.7.0



36
37
38
39
40
41
# File 'lib/hanami/model/sql/entity/schema.rb', line 36

def initialize(registry, relation, mapping)
  attributes  = build(registry, relation, mapping)
  @schema     = Types::Coercible::Hash.schema(attributes)
  @attributes = Hash[attributes.map { |k, _| [k, true] }]
  freeze
end

Instance Method Details

#attribute?(name) ⇒ TrueClass, FalseClass

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.

Check if the attribute is known

Parameters:

  • name (Symbol)

    the attribute name

Returns:

  • (TrueClass, FalseClass)

    the result of the check

Since:

  • 0.7.0



67
68
69
# File 'lib/hanami/model/sql/entity/schema.rb', line 67

def attribute?(name)
  attributes.key?(name)
end

#call(attributes) ⇒ Object Also known as: []

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.

Process attributes

Parameters:

  • attributes (#to_hash)

    the attributes hash

Raises:

  • (TypeError)

    if the process fails

Since:

  • 1.0.1



51
52
53
# File 'lib/hanami/model/sql/entity/schema.rb', line 51

def call(attributes)
  schema.call(attributes)
end