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

Allow defining enum value mapping #2

Open
julik opened this issue Jun 10, 2024 · 0 comments
Open

Allow defining enum value mapping #2

julik opened this issue Jun 10, 2024 · 0 comments

Comments

@julik
Copy link
Collaborator

julik commented Jun 10, 2024

At the moment state_machine_enum relies on Postgres enums. The values for the enum attribute are collected from the collector, but there is no way to map them either to specific integers (closed: 0, open: 1) or to strings (closed: "CLOSED", open: "OPEN") as they are picked up from the Collector. At the moment the only mapping we support is from string to itself - closed: "closed", open: "open"} We need a way to make this customisable - one way could be like this:

state_machine_enum :foo do |sm|
    sm.value_map { |enum| enum_sym.to_s.upcase }
end

or similar. Or we need to add a test that the passed mapping overrides the one received from the Collector and there is a check if there is a discrepancy (come to think of it - this might even be better, as the standard Rails way of defining an enum can then be preserved)

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

1 participant