Class: Hanami::Entity::Schema::Definition::Dsl Private
- Inherits:
-
Object
- Object
- Hanami::Entity::Schema::Definition::Dsl
- 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 DSL
Constant Summary collapse
- TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[schema strict weak permissive strict_with_defaults symbolized].freeze
- DEFAULT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
TYPES.first
Class Method Summary collapse
- .build(type, &blk) ⇒ Object private
Instance Method Summary collapse
-
#attribute(name, type) ⇒ Object
private
Define an attribute.
-
#initialize(&blk) ⇒ Dsl
constructor
private
A new instance of Dsl.
- #to_h ⇒ Object private
Constructor Details
#initialize(&blk) ⇒ 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.
Returns a new instance of Dsl.
118 119 120 121 |
# File 'lib/hanami/entity/schema.rb', line 118 def initialize(&blk) @attributes = {} instance_eval(&blk) end |
Class Method Details
.build(type, &blk) ⇒ 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.
108 109 110 111 112 113 114 |
# File 'lib/hanami/entity/schema.rb', line 108 def self.build(type, &blk) type ||= DEFAULT_TYPE raise Hanami::Model::Error.new("Unknown schema type: `#{type.inspect}'") unless TYPES.include?(type) attributes = new(&blk).to_h [attributes, Hanami::Model::Types::Coercible::Hash.__send__(type, attributes)] end |
Instance Method Details
#attribute(name, type) ⇒ 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.
Define an attribute
149 150 151 |
# File 'lib/hanami/entity/schema.rb', line 149 def attribute(name, type) @attributes[name] = type end |
#to_h ⇒ 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.
155 156 157 |
# File 'lib/hanami/entity/schema.rb', line 155 def to_h @attributes end |