class App::Repository::UserRepository

Overview

UserRepository manages Entity::UserEntity array

To create an UserRepository:

mary = Entity::UserEntity.new 1 "mary" "secret" "[email protected]"
repository = Repository::UserRepository.new [mary]

Defined in:

app/repository/user_repository.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(entries : Array(App::Entity::UserEntity) = [] of UserEntity) #

[View source]

Instance Method Detail

def create(entry) #

Creates an entity

#entry is an instance which attributes are at least corresponding to the ones in Entity::UserEntity

As an example:

class UserEntry
  @id : Int32
  @name:  String
  @password: String
  @email: String
  @created_at: Time
  @updated_at: Time
  property :id, :name, :password, :email, :created_at, :updated_at
end
entry = UserEntry.new
entry.id = 1
entry.name = "mary"
entry.password = "secret"
entry.email = "[email protected]"
entry.created_at = Time.new
entry.updated_at = Time.new
repository.create(entry) # => `Entity::UserEntity`

Returns an instance of Entity::UserEntity


[View source]
def find(id : Int32) #

Finds an entity in the #entries given its id

repository.find(1) # => `#mary`

Returns a Entity::UserEntity if found


[View source]
def find_by_name(name : String) #

Finds an entity in the #entries given its name

repository.find_by_name("mary") # => `#mary`

Returns a Entity::UserEntity if found


[View source]
def last #
repository.last # => `#mary`

Returns last Entity::UserEntity in #entries


[View source]