-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add .defined_schema method #98
Conversation
spec/support/schema_spec.rb
Outdated
context 'json schema defined' do | ||
let(:instance) { WithSchema } | ||
it do | ||
expect(instance.defined_schema).to eq({ name: String, age: Integer }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
lib/surrealist/class_methods.rb
Outdated
# Person.defined_schema | ||
# # => { name: String } | ||
def defined_schema | ||
instance_variable_get('@__surrealist_schema') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we raise UnknownSchemaError
or any other error if any schema has been defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a spec for the same logic but with custom serializers?
lib/surrealist/class_methods.rb
Outdated
# Person.defined_schema | ||
# # => { name: String } | ||
def defined_schema | ||
instance_variable_get('@__surrealist_schema') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we should
CHANGELOG.md
Outdated
# Next (unreleased) | ||
|
||
## Added | ||
* `.defined_schema` to return the schema that has been defined with `json_schema` ([@glaucocustodio][]) [#93](https://github.com/nesaulov/surrealist/pull/98) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add a link to yourself at the end of the file in order for this to work, see line 95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec/support/schema_spec.rb
Outdated
describe '.defined_schema' do | ||
context 'json schema defined' do | ||
let(:instance) { WithSchema } | ||
it do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A space between let
and it
is missing.
Also I would suggest to add a specification to it
, like it 'returns the defined json_schema' do
spec/support/schema_spec.rb
Outdated
|
||
context 'json schema not defined' do | ||
let(:instance) { WithoutSchema } | ||
it do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
class CatSerializer < Surrealist::Serializer
json_schema { { age: Integer, age_group: String } }
def age_group
age <= 5 ? 'kitten' : 'cat'
end
end class Cat
include Surrealist
attr_reader :age
surrealize_with CatSerializer
def initialize(age)
@age = age
end
end In this case of custom serializer, should |
I think yes, it should. And if there are many serializers available (via |
Take a look now please @nesaulov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the url text in changelog, the rest looks good to me
CHANGELOG.md
Outdated
# Next (unreleased) | ||
|
||
## Added | ||
* `.defined_schema` to return the schema that has been defined with `json_schema` ([@glaucocustodio][]) [#93](https://github.com/nesaulov/surrealist/pull/98) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done @nesaulov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @glaucocustodio!
🤔 there is something wrong with rspec or rom on travis |
The problem was with dry-types and rom-rb compatibility, see rom-rb/rom#494 |
Thank you @glaucocustodio! 🎉 |
No description provided.