rails-settings-cached 2.7.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d45081eacc51de459cd0bc48469430474cd561386e924b40996bd5f66c1299e5
4
- data.tar.gz: 485e2df525a6d3b66dfed0c0b5935aa8134b13ae0b0528d1fae536e5b19e4ae2
3
+ metadata.gz: 70c3d68c88fbd1a2a3cc1e9f78a45e06fc7b7a6df4698137e2a4ea6c77a27e33
4
+ data.tar.gz: fd6ecee62edad7a5ca942fbe7e102ae6e3f075ea471e120dcc5a5f1d5f3fdb33
5
5
  SHA512:
6
- metadata.gz: 6651da35fec5737f76192ec01f0980ea45a85c69efb768c22edbce29b490f29dfa2498798b5af6d45a126955a3fe72bf2fa1ae76bd249237b83f408f7bba72c4
7
- data.tar.gz: b96670e501b9c5aff237b02fd2da2560b654dd2835322b2e64e28679e3edf646ee940f2f2ffe69bfa7d851732ac4844bb47b01e292f4ef4b5f04e587977f8c21
6
+ metadata.gz: 0d0c55d7a8f19adbfa81868c76a1d36f67aa37d27ad33051b7a8bf6ec323d0d4b57cc442c29b43be8c8799cfa3968f958f29fb1f104230dc79478294f09d2a59
7
+ data.tar.gz: 699e9e77f1d4d130e9493c7c379f1aade95b7f589401652912741f5e13eec4816b0a8eee308b55504ad3acfc2613af41113051d6a5655df399d27ed59015bd5f
data/README.md CHANGED
@@ -34,7 +34,7 @@ class Setting < RailsSettings::Base
34
34
  scope :application do
35
35
  field :app_name, default: "Rails Settings", validates: { presence: true, length: { in: 2..20 } }
36
36
  field :host, default: "http://example.com", readonly: true
37
- field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp] } }, option_values: %w[en zh-CN]
37
+ field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp] } }, option_values: %w[en zh-CN jp], help_text: "Bla bla ..."
38
38
  field :admin_emails, type: :array, default: %w[admin@rubyonrails.org]
39
39
 
40
40
  # lambda default value
@@ -46,14 +46,14 @@ class Setting < RailsSettings::Base
46
46
  scope :limits do
47
47
  field :user_limits, type: :integer, default: 20
48
48
  field :exchange_rate, type: :float, default: 0.123
49
- field :captcha_enable, type: :boolean, default: true, group: :limits
49
+ field :captcha_enable, type: :boolean, default: true
50
50
  end
51
51
 
52
52
  field :notification_options, type: :hash, default: {
53
53
  send_all: true,
54
54
  logging: true,
55
55
  sender_email: "foo@bar.com"
56
- }, group: :advanced
56
+ }
57
57
 
58
58
  field :readonly_item, type: :integer, default: 100, readonly: true
59
59
  end
@@ -61,6 +61,8 @@ end
61
61
 
62
62
  You must use the `field` method to statement the setting keys, otherwise you can't use it.
63
63
 
64
+ The `scope` method allows you to group the keys for admin UI.
65
+
64
66
  Now just put that migration in the database with:
65
67
 
66
68
  ```bash
@@ -149,13 +151,16 @@ Settng.editable_keys
149
151
  Setting.readonly_keys
150
152
  => ["host", "readonly_item"]
151
153
 
152
- # Get options of field
154
+ # Get field
153
155
  Setting.get_field("host")
154
156
  => { scope: :application, key: "host", type: :string, default: "http://example.com", readonly: true }
155
157
  Setting.get_field("app_name")
156
158
  => { scope: :application, key: "app_name", type: :string, default: "Rails Settings", readonly: false }
157
159
  Setting.get_field(:user_limits)
158
160
  => { scope: :limits, key: "user_limits", type: :integer, default: 20, readonly: false }
161
+ # Get field options
162
+ Setting.get_field("default_locale")[:options]
163
+ => { option_values: %w[en zh-CN jp], help_text: "Bla bla ..." }
159
164
  ```
160
165
 
161
166
  #### Get All defined fields
@@ -37,9 +37,16 @@ module RailsSettings
37
37
  _define_field(key, **opts)
38
38
  end
39
39
 
40
- def scope(name)
40
+ alias_method :_rails_scope, :scope
41
+ def scope(*args, &block)
42
+ name = args.shift
43
+ body = args.shift
44
+ if body.respond_to?(:call)
45
+ return _rails_scope(name, body, &block)
46
+ end
47
+
41
48
  @scope = name.to_sym
42
- yield
49
+ yield block
43
50
  @scope = nil
44
51
  end
45
52
 
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.7.0"
6
+ "2.7.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-settings-cached
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails