DmitryTsepelev / store_model

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

Provide convenience methods for instantiating StoreModel::Models with type behavior #191

Closed bengladwell closed 2 weeks ago

bengladwell commented 2 weeks ago

We were initially confused about why classes that extend StoreModel::Model did not have the unknown attribute behavior when initialized with new. However, we figured out that instances must be created from a "type", i.e. with .to_type.cast_value. Would you accept a PR that adds two class methods to StoreModel::Model to make this a little more simple?

      def from_value(value)
        to_type.cast_value(value)
      end

      def from_values(values)
        to_array_type.cast_value(values)
      end

?