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


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

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


199
200
201
# File 'lib/hanami/entity/schema.rb', line 199

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


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

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