Skip to content

Feature parity/comparison for ActiveRecord enum types #429

@crimson-knight

Description

@crimson-knight

I'm currently working on syncing a Rails app with a Crystal app using Jennifer and Mosquito to handle my background processing.

I have an ActiveRecord model that uses a hash enum for a particular column, like this:

class MyClass < ApplicationRecord
  # bunch of code here
  enum type: {
    my_type_1: "my type 1",
    my_type_2: "my type 2"
  }
end

I can then use it in this way:

my_class = MyClass.new(type: :my_type_1)

my_class.type # returns: "my_type_1"
my_class.type = "my type 1" # sets the `type` attribute to "my_type_1"
my_class.type = :my_type_1  # sets the `type` attribute to "my_type_1"

This doesn't work in Crystal because Enums can only be integer values and that's fine, but it would be nice to make the experience feels like it's a feature of Jennifer.

I can work my solution into the code base and create a PR (it'll probably be at least a few weeks), but I wanted to see if it's a feature you'd like to see added.

Please let me know if you'd like this type of functionality added to Jennifer :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions