Skip to content
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

Replace the types public API with the Field public API #9

Closed
pwalsh opened this issue Oct 10, 2016 · 5 comments
Closed

Replace the types public API with the Field public API #9

pwalsh opened this issue Oct 10, 2016 · 5 comments

Comments

@pwalsh
Copy link
Member

pwalsh commented Oct 10, 2016

In the reference implementation we moved from exposing types to exposing a Field API. This was happening at the same time as the ruby port, so understandably is not here.

Also I think the change from convert_* to cast_* semantics occurred at around the same time. Example.

it would be good to move the Ruby lib to the Field API.

# fields (new)
Field({'type': 'number'}).cast_value()

# types (old)
types.NumberType({'type': 'number'}).convert_value()

cc @roll

@roll
Copy link
Member

roll commented Oct 10, 2016

This API also allows to return to user Field instance from Schema:

schema = Schema('descriptor.json')
field = schema.get_field('name') # the same for schema.fields etc
field.name
field.cast_value('value')

It's more useful to the user than just a dict. You could see it on the stack reference - frictionlessdata/frictionlessdata.io#289 (also there are some discrepancies - no Schema.descriptor in rb etc - because both works was going in parallel).

PS.
I suppose one important thing - we're trying to use descriptor term consistently for argument names - Schema(descriptor), Field(descriptor), DataPackage(descriptor), Resource(descriptor).

@roll
Copy link
Member

roll commented Oct 12, 2016

@roll The schema and field connections are defined in https://github.com/theodi/jsontableschema.rb/blob/feature-add-field/lib/jsontableschema/model.rb - which is a Ruby module which is included in schema.rb - I've split a lot of things out into modules, which keeps things neater.

@pezholio
So when we iterate over schema.fields we get Fields instances. Correct? The same for schema.get_field() -> Field etc?

@pezholio
Copy link
Contributor

That's right 👍

@roll
Copy link
Member

roll commented Oct 12, 2016

Thanks! Also starting to understand Ruby a little bit (found load_fields!=)
👍

@pezholio
Copy link
Contributor

Yeah, it wasn't in the most sensible place before. Makes much more sense to have it in Model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants