huacnlee / rails-settings-cached

Global settings for your Rails application.
Other
1.06k stars 202 forks source link

Default Proc setting does not work if it is readonly #211

Closed heraldofsolace closed 3 years ago

heraldofsolace commented 3 years ago

I have a settings class where I want one field to be dependent of the other, but readonly -

class Setting < RailsSettings::Base
  cache_prefix { "v1" }

  field :default_locale, default: "en", type: :string
  field :current_school_year_start, default: Time.now.year, type: :integer
  field :current_school_year_end, default: -> { self.current_school_year_start + 1 }, type: :integer, readonly: true

end

When I call Setting.current_school_year_end, I get #<Proc:0x0000560e4ecef538 /development_works/UPI/app/models/setting.rb:22 (lambda)>, but if I remove the readonly part it works fine.