v2.9.0
What's Changed
- Adds Ruby 3.2 support by @berkos in #232
- Add ability to define custom data types by @MrKirat in #235
Custom type for setting
You can write your custom field type by under RailsSettings::Fields
module.
For example
module RailsSettings
module Fields
class YesNo < ::RailsSettings::Fields::Base
def serialize(value)
case value
when true then "YES"
when false then "NO"
else raise StandardError, 'invalid value'
end
end
def deserialize(value)
case value
when "YES" then true
when "NO" then false
else nil
end
end
end
end
end
Now you can use yes_no
type in you setting:
class Setting
field :custom_item, type: :yes_no, default: 'YES'
end
irb> Setting.custom_item = 'YES'
irb> Setting.custom_item
true
irb> Setting.custom_item = 'NO'
irb> Setting.custom_item
false
New Contributors
Full Changelog: v2.8.3...v2.9.0