Skip to content

Releases: huacnlee/rails-settings-cached

v2.8.0

14 Sep 15:13
bd2c7ae
Compare
Choose a tag to compare
  • Add Middleware for only enable RequestCache in Rails request context. #219, #182

v2.7.1

12 Jul 13:59
Compare
Choose a tag to compare
  • Fix #215 keep scope method compatible with ActiveRecord scope.

v2.7.0

08 Jul 07:30
Compare
Choose a tag to compare
  • 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

08 Jul 07:21
Compare
Choose a tag to compare
  • Allows call key in Setting instance to support use keys in ActionView helpers.
    • Fix #212 not can use f.select with Setting instance method.
  • Brake Changes: Limit use var, value as Setting key, now will raise error.

v2.5.3

08 Jul 07:21
Compare
Choose a tag to compare
  • Improve implement for avoid use eval method.
  • Fix #211, support Proc default value for readonly field.

v2.5.2

08 Jul 07:22
Compare
Choose a tag to compare
  • Avoid allocate string on get value.

v2.5.1

08 Jul 07:22
Compare
Choose a tag to compare
  • Do validate on directly assignment (#202)
irb> Setting.default_locale = "foo"
ActiveRecord::RecordInvalid: (Validation failed: Default locale is not included in [zh-CN, en, jp])

v2.5.0

08 Jul 07:22
Compare
Choose a tag to compare
  • 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

08 Jul 07:22
527d6b9
Compare
Choose a tag to compare
  • Fix request_cache for backward compatible with Rails 5.0.x;
  • No effect for Rails 5.2+;

In Rails 5.0:

# You must add request_store dependency in to you Gemfile
gem "request_store"
gem "rails-settings-cached"

v2.4.0

08 Jul 07:22
Compare
Choose a tag to compare