Skip to content

Commit

Permalink
Add usage section to README
Browse files Browse the repository at this point in the history
A new section has been added to the README which outlines how to use the Datory serialization library. Included are examples of how to serialize and deserialize a user object, involving multiple DTO classes.
  • Loading branch information
afuno committed Apr 21, 2024
1 parent 9fc544f commit 408080b
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a href="https://github.com/servactory/datory/releases"><img src="https://img.shields.io/github/release-date/servactory/datory" alt="Release Date"></a>
</p>

## Documentation
## Documentation (soon)

See [datory.servactory.com](https://datory.servactory.com) for documentation.

Expand All @@ -15,6 +15,56 @@ See [datory.servactory.com](https://datory.servactory.com) for documentation.
gem "datory"
```

### Usage

#### Serialize

```ruby
user = User.find(...)

UserDto.serialize(user)
```

#### Deserialize

```ruby
UserDto.deserialize(json)
```

#### Examples

##### User

```ruby
class UserDto < Datory::Base
string :id
string :firstname, as: :first_name
string :lastname, as: :last_name
string :email
string :birthDate, as: :birth_date, output: ->(value:) { value.to_s }

one :login, include: UserLoginDto

many :addresses, include: UserAddressDto

string :phone
string :website

one :company, include: UserCompanyDto
end
```

```ruby
class UserLoginDto < Datory::Base
string :uuid
string :username
string :password
string :md5
string :sha1
string :registered
end
```

## Contributing

This project is intended to be a safe, welcoming space for collaboration.
Expand Down

0 comments on commit 408080b

Please sign in to comment.