Releases: huacnlee/rails-settings-cached
Releases · huacnlee/rails-settings-cached
v2.8.0
v2.7.1
v2.7.0
- Allows define field for assignment more options, and then you can get option by
get_field
. - Export
Setting.defined_fields
method for get all fields. - Add optional
scope
method to allows us grouping fields on if we need.
Use case:
class Setting < RailsSettings::Base
# cache_prefix { "v1" }
scope :application do
field :app_name, default: "Rails Settings", validates: { presence: true, length: { in: 2..20 } }
field :host, default: "http://example.com", readonly: true
field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp] } }, option_values: %w[en jp zh-CN], foo: 123
field :admin_emails, type: :array, default: %w[admin@rubyonrails.org]
# lambda default value
field :welcome_message, type: :string, default: -> { "welcome to #{self.app_name}" }, validates: { length: { maximum: 255 } }
# Override array separator, default: /[\n,]/ split with \n or comma.
field :tips, type: :array, separator: /[\n]+/
end
scope :limits do
field :user_limits, type: :integer, default: 20
field :exchange_rate, type: :float, default: 0.123
field :captcha_enable, type: :boolean, default: true
end
field :notification_options, type: :hash, default: {
send_all: true,
logging: true,
sender_email: "foo@bar.com"
}
field :readonly_item, type: :integer, default: 100, readonly: true
end
Setting.get_field(:default_locale)[:options]
=> { option_values: %w[en zh-CN], foo: 123}
field_groups = Setting.defined_fields.select { |field| }.group_by { |field| field[:scope] || :other }
field_groups.keys
=> [:application, :limit, :other]
v2.6.0
v2.5.3
v2.5.2
v2.5.1
v2.5.0
- Add
validates
options to special the Rails Validation for fields (#201)
class Setting < RailsSettings::Base
# cache_prefix { "v1" }
field :app_name, default: "Rails Settings", validates: { presence: true, length: { in: 2..20 } }
field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp], message: "is not included in [zh-CN, en, jp]" } }
end
v2.4.1
v2.4.0
- Use ActiveSupport::CurrentAttributes instead of the request_store for storage request cache.
- Remove request_store dependency.