Skip to content

v2.9.0

Compare
Choose a tag to compare
@huacnlee huacnlee released this 29 May 06:12
· 19 commits to main since this release

What's Changed

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