Class: Hanami::Entity::Schema::Definition Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/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.

Schema definition

Since:

  • 0.7.0

Defined Under Namespace

Classes: Dsl

Instance Method Summary collapse

Constructor Details

#initialize(type = nil, &blk) ⇒ Hanami::Entity::Schema::Dsl

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.

Instantiate a new DSL instance for an entity

Parameters:

  • blk (Proc)

    the block that defines the attributes

Raises:

  • (LocalJumpError)

Since:

  • 0.7.0



168
169
170
171
172
173
174
# File 'lib/hanami/entity/schema.rb', line 168

def initialize(type = nil, &blk)
  raise LocalJumpError unless block_given?

  @attributes, @schema = Dsl.build(type, &blk)
  @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



201
202
203
# File 'lib/hanami/entity/schema.rb', line 201

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

#call(attributes) ⇒ 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.

Process attributes

Parameters:

  • attributes (#to_hash)

    the attributes hash

Raises:

  • (TypeError)

    if the process fails

  • (ArgumentError)

    if data is missing, or unknown keys are given

Since:

  • 0.7.0



185
186
187
188
189
190
191
# File 'lib/hanami/entity/schema.rb', line 185

def call(attributes)
  schema.call(attributes)
rescue Dry::Types::SchemaError => exception
  raise TypeError.new(exception.message)
rescue Dry::Types::MissingKeyError, Dry::Types::UnknownKeysError => exception
  raise ArgumentError.new(exception.message)
end