Skip to content

Commit

Permalink
Improve parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
zinahia committed Aug 23, 2024
1 parent 29bde80 commit c7d0c75
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ avro.encode({ "name" => "Jane", "age" => 28 }, schema_name: "person")
# Avro::SchemaValidator::ValidationError exception
avro.encode({ "titl" => "hello, world" }, schema_name: "person", validate: true)

# If you do not want to register the schema in case it does not exist, you can pass the read_only option
avro.encode({ "name" => "Jane", "age" => 28 }, schema_name: "person", read_only: true)
# If you do not want to register the schema in case it does not exist, you can pass the register_schemas option as false
avro.encode({ "name" => "Jane", "age" => 28 }, schema_name: "person", register_schemas: false)
```

### Inter-schema references
Expand Down
38 changes: 19 additions & 19 deletions lib/avro_turf/messaging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,32 @@ def initialize(

# Encodes a message using the specified schema.
#
# message - The message that should be encoded. Must be compatible with
# the schema.
# schema_name - The String name of the schema that should be used to encode
# the data.
# namespace - The namespace of the schema (optional).
# subject - The subject name the schema should be registered under in
# the schema registry (optional).
# version - The integer version of the schema that should be used to decode
# the data. Must match the schema used when encoding (optional).
# schema_id - The integer id of the schema that should be used to encode
# the data.
# validate - The boolean for performing complete message validation before
# encoding it, Avro::SchemaValidator::ValidationError with
# a descriptive message will be raised in case of invalid message.
# read_only - The boolean that indicates whether or not the schema should be
# registered in case it does not exist, or if it should be fetched
# from the registry without registering it (read_only: true).
# message - The message that should be encoded. Must be compatible with
# the schema.
# schema_name - The String name of the schema that should be used to encode
# the data.
# namespace - The namespace of the schema (optional).
# subject - The subject name the schema should be registered under in
# the schema registry (optional).
# version - The integer version of the schema that should be used to decode
# the data. Must match the schema used when encoding (optional).
# schema_id - The integer id of the schema that should be used to encode
# the data.
# validate - The boolean for performing complete message validation before
# encoding it, Avro::SchemaValidator::ValidationError with
# a descriptive message will be raised in case of invalid message.
# register_schemas - The boolean that indicates whether or not the schema should be
# registered in case it does not exist, or if it should be fetched
# from the registry without registering it (register_schemas: false).
#
# Returns the encoded data as a String.
def encode(message, schema_name: nil, namespace: @namespace, subject: nil, version: nil, schema_id: nil, validate: false,
read_only: false)
register_schemas: true)
schema, schema_id = if schema_id
fetch_schema_by_id(schema_id)
elsif subject && version
fetch_schema(subject: subject, version: version)
elsif schema_name && read_only
elsif schema_name && !register_schemas
fetch_schema_by_body(subject: subject, schema_name: schema_name, namespace: namespace)
elsif schema_name
register_schema(subject: subject, schema_name: schema_name, namespace: namespace)
Expand Down
8 changes: 4 additions & 4 deletions spec/messaging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@
expect { avro.encode(message, subject: 'missing', version: 1) }.to raise_error(AvroTurf::SchemaNotFoundError)
end

it 'raises AvroTurf::SchemaNotFoundError when the schema does not exist on registry and read_only true' do
expect { avro.encode(city_message, schema_name: 'city', read_only: true) }.
it 'raises AvroTurf::SchemaNotFoundError when the schema does not exist on registry and register_schemas false' do
expect { avro.encode(city_message, schema_name: 'city', register_schemas: false) }.
to raise_error(AvroTurf::SchemaNotFoundError, "Schema with structure: #{city_schema} not found on registry")
end

it 'encodes with read_only true when the schema exists on the registry' do
data = avro.encode(message, schema_name: 'person', read_only: true)
it 'encodes with register_schemas false when the schema exists on the registry' do
data = avro.encode(message, schema_name: 'person', register_schemas: false)
expect(avro.decode(data, schema_name: 'person')).to eq message
end

Expand Down

0 comments on commit c7d0c75

Please sign in to comment.