DmitryTsepelev / store_model

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

Fixed issues with enum that contains type float #186

Closed zabil-maooz closed 1 month ago

zabil-maooz commented 1 month ago

When creating enums that contains enum value type float, it throws errors of invalid type. This PR fixes the issue.

Details:

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 value 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.

Issue reported

DmitryTsepelev commented 1 month ago

Hey hey, looks like we need to do something with specs.

zabil-maooz commented 1 month ago

Hey hey, looks like we need to do something with specs.

I have force pushed the commit and updated the specs as well. Thanks for the reminder.

DmitryTsepelev commented 1 month ago

Let's give it a try, thank you 🙂

zabil-maooz commented 1 month ago

Let's give it a try, thank you 🙂

You are welcome. And thanks for merging the PR. 😃