DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.06k stars 86 forks source link

Enum not handled correctly #185

Open zabil-maooz opened 20 hours ago

zabil-maooz commented 20 hours ago

I am having a scenario where I need my enum to be defined as { key => float } mapping. This is my class

class Inputs
    include StoreModel::Model

    attribute :in_temp, :float, default: 29
    attribute :ext_temp, :float, default: 50
    attribute :rel_humid, :float, default: 70
    attribute :ins_thick, :float, default: 10

    enum :surf_emis, in: {
      high_surface: '10.0',
      medium_surface: '8.0',
      low_surface: '5.7'
    }, default: :medium_surface

    validates :in_temp, :ext_temp, :rel_humid, :surf_emis, :ins_thick, presence: true
  end

Now the issue is, It only works if keys value pair is { key => integer }, but for integer I can not handle 5.7 I tried using string but it also throws error. I tried using float but it also throws error.

Only working case is integer which is not applicable in my case.

zabil-maooz commented 20 hours ago

@DmitryTsepelev I have opened a PR for the fix of this issue.
Please have a look at it and let me know if you need anything.

PR Link: https://github.com/DmitryTsepelev/store_model/pull/186