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(&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



155
156
157
158
159
160
# File 'lib/hanami/entity/schema.rb', line 155

def initialize(&blk)
  raise LocalJumpError unless block_given?
  @attributes, @schema = Dsl.build(&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



184
185
186
# File 'lib/hanami/entity/schema.rb', line 184

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

Since:

  • 0.7.0



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

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