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

Attribute type aliases with Shale::Type.register and Shale::Type.lookup #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

admtnnr
Copy link

@admtnnr admtnnr commented Oct 1, 2024

Design

Introduces Shale::Type.register and Shale::Type.lookup that the Shale::Mapper uses to map a short symbol alias to a full Shale::Type::Value subclass.

Existing built-in types have been registered with aliases, with the following exceptions:

  • Shale::Type::Value - base class, couldn't come up with a good use case why this would be used directly enough to warrant an alias
  • Shale::Type::Complex - private API, shouldn't be used directly anyway

Out of Scope

I left the lookups for the XML/JSON schema compiler and generation alone such that they continue to stamp in the full class name instead of the symbol alias, but can switch those if you'd prefer.

I was going to swap them, but felt that the name method returning something like ":string" felt a bit more awkward than the full class name as it would need to have the : prefix.

Resolves #43.

Copy link
Owner

@kgiszczak kgiszczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks really great. Once you add those two small additions I asked it will be ready to merge.

@@ -1208,12 +1208,12 @@ PersonMapper.to_json(person, pretty: true)

Shale supports these types out of the box:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a section to the readme, describing that passing a class as a type is also valid, with some small example?

@@ -8,14 +8,14 @@ module ShaleMapperTesting
BAR_DEFAULT_PROC = -> { 'bar' }

class Parent < Shale::Mapper
attribute :foo, Shale::Type::String
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test case using classes?

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

Successfully merging this pull request may close these issues.

Attribute Type Registry
2 participants