lib/hanami/entity/schema.rb in hanami-model-1.0.0.beta2 vs lib/hanami/entity/schema.rb in hanami-model-1.0.0.beta3
- old
+ new
@@ -9,12 +9,11 @@
# @api private
#
# @example SQL Automatic Setup
# require 'hanami/model'
#
- # class Account
- # include Hanami::Entity
+ # class Account < Hanami::Entity
# end
#
# account = Account.new(name: "Acme Inc.")
# account.name # => "Hanami"
#
@@ -22,13 +21,11 @@
# account.foo # => NoMethodError
#
# @example Non-SQL Manual Setup
# require 'hanami/model'
#
- # class Account
- # include Hanami::Entity
- #
+ # class Account < Hanami::Entity
# attributes do
# attribute :id, Types::Int
# attribute :name, Types::String
# attribute :codes, Types::Array(Types::Int)
# attribute :users, Types::Array(User)
@@ -44,12 +41,11 @@
# account.foo # => NoMethodError
#
# @example Schemaless Entity
# require 'hanami/model'
#
- # class Account
- # include Hanami::Entity
+ # class Account < Hanami::Entity
# end
#
# account = Account.new(name: "Acme Inc.")
# account.name # => "Acme Inc."
#
@@ -115,9 +111,29 @@
#
# @param name [Symbol] the attribute name
# @param type [Dry::Types::Definition] the attribute type
#
# @since 0.7.0
+ #
+ # @example
+ # require 'hanami/model'
+ #
+ # class Account < Hanami::Entity
+ # attributes do
+ # attribute :id, Types::Int
+ # attribute :name, Types::String
+ # attribute :codes, Types::Array(Types::Int)
+ # attribute :users, Types::Array(User)
+ # attribute :email, Types::String.constrained(format: /@/)
+ # attribute :created_at, Types::DateTime
+ # end
+ # end
+ #
+ # account = Account.new(name: "Acme Inc.")
+ # account.name # => "Acme Inc."
+ #
+ # account = Account.new(foo: "bar")
+ # account.foo # => NoMethodError
def attribute(name, type)
@attributes[name] = type
end
# @since 0.7.0