kgiszczak / shale

Shale is a Ruby object mapper and serializer for JSON, YAML, TOML, CSV and XML. It allows you to parse JSON, YAML, TOML, CSV and XML data and convert it into Ruby data structures, as well as serialize data structures into JSON, YAML, TOML, CSV or XML.
https://shalerb.org/
MIT License
626 stars 19 forks source link

Attribute Type Registry #43

Open admtnnr opened 4 days ago

admtnnr commented 4 days ago

Hey Kamil! I just started using Shale to clean up our in-house API clients and so far things are going well! I was wondering if you would be open to introducing an attribute type registry/lookup table to make the Shale mapping process a bit less verbose and streamline the UX?

I'm imagining something similar (if not the exact same) as what ActiveModel::Attributes does with the symbol to type lookup done through ActiveModel::Type's lookup and register methods. That would allow us to do something like the following which I personally think cuts down on the cognitive overhead and makes reading the class a little easier. What do you think? I'm happy to submit a PR if you're open to it.


class Person < Shale::Mapper
  attribute :first_name, :string
  attribute :last_name, :string
  attribute :date_of_birth, :date
end
kgiszczak commented 4 days ago

Hey, PR is welcome

admtnnr commented 2 days ago

@kgiszczak PR has been opened, let me know what you think. 🙂

kgiszczak commented 2 days ago

Thank you, I'll review it on the weekend.