Skip to content

Commit

Permalink
Merge pull request #5 from shoplineapp/feature/add-release-note-and-a…
Browse files Browse the repository at this point in the history
…vro_doc

release(): update readme and changelog for 1.0.0
  • Loading branch information
rayway30419 authored Jul 4, 2023
2 parents 25c7c09 + 6b8b3ac commit 576ee48
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## [Unreleased]

---

## [0.1.0] - 2023-03-01

- Initial release

## [1.0.0] - 2023-07-04

- Support generate avro schema from mongoid model
- support `avro_format` and `avro_doc`
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Mongoid::Avro

`mongoid-avro` is a Ruby gem that allows you to convert a `Mongoid` Model schema to an Avro schema. This can be useful if you want to use Avro serialization with your Mongoid data.
The `mongoid-avro` is a Ruby gem that allows you to convert a `Mongoid` Model schema into an Avro schema. This can be useful if you want to use Avro serialization with your Mongoid data.


---

## Installation

Add mongoid-avro to your Gemfile:
To install mongoid-avro, add it to your Gemfile:

```ruby
gem 'mongoid-avro'
```

And then execute:
Then, execute the following command:



```ruby
bundle install
Expand All @@ -28,7 +32,7 @@ class MyModel
# ...
end
```
2. Optionally, specify the Avro format for each field using the avro_format option:
2. Optionally, you can specify the Avro format for each field using the `avro_format` option:

```ruby
class MyModel
Expand All @@ -47,22 +51,37 @@ class MyModel
# ...
end
```
The avro_format option can be a string, symbol, or hash.
The `avro_format` option can be a `String`, `Symbol`, or `Hash`.

2. Optionally, you can specify the `avro_doc` option to add a description of the field. It will be used as the `doc` of the field.


```ruby
class Person
include Mongoid::Document
include Mongoid::Avro

field :unique_name, type: String, avro_doc: 'The name of the person which is unique.'
end
```

3. To generate the Avro schema for your model, call the `.generate_avro_schema method` :

3. To generate the Avro schema for your model, call generate_avro_schema:

```ruby
schema = MyModel.generate_avro_schema(namespace: 'my.namespace')
```

You can pass an optional namespace parameter to specify the namespace for the Avro schema.
You can pass an optional namespace parameter to specify the namespace for the Avro schema. The method returns an `Avro::Schema` object.


The method returns an `Avro::Schema`.

4. (Optional) Generate avro schema to json
4. (Optional) Generate Avro schema as JSON:
```ruby
schema.to_avro.to_json
```

---
## Field type transform login
### Primitive Types
Expand Down Expand Up @@ -112,7 +131,7 @@ schema.to_avro.to_json
}
```
#### Hash: `string`
- expected to be serialized as json string
- Expected to be serialized as a JSON string.

### Embedded document
#### Embeds One
Expand Down

0 comments on commit 576ee48

Please sign in to comment.