rails-settings-cached 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 765057576ddcdb19d9f394f1844950f03e8c70944abd9b104e70824f60f7e0e5
4
- data.tar.gz: 0d2a2c4aa7560d96bee3a0c1a0d50f7cb89bffd5c650ae47f2bd6169c0d12b6e
3
+ metadata.gz: 85279c41b179aa65d668a48d4d18e73b5fe886be9cd8235dc2acdb54c3beb5da
4
+ data.tar.gz: 516991953aa7698cf86511512d863b7903d1ec5ad648a69c386501413a75ac86
5
5
  SHA512:
6
- metadata.gz: 908f7ae3d8e01710f9df4cb32a77b2302129107bcd34254cb5237fc5f5b98f2e4007fe315751ab3fd7e2212e14a0db133f796f994b0bd6a1cee48768717a01a9
7
- data.tar.gz: fe611e7af4ac5ca72a98040c63b0475833878ac6f11b82953fd80458bb6b96311fff7fc174f890171f466f724be809cd334bc184b0cb0c8c7b3ae94f5fbee28f
6
+ metadata.gz: 742596dc7e47c3d31ea64ecf54d96cae5885938076c2704aebe5f3e94701627631d19a8480f24ef97dc1861a8e1a1cab33c6f3aefd56ff755f88ef47c1380401
7
+ data.tar.gz: aa7b9a3ba2443a7ac6cb12150c196247bfd543e086b4eea1199f83eca1035ddefc1bcb32ae5d01cf9c3448dcd2f5c651dd9a73c8dab22600d28f202ef7d1f4a6
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ## Rails Settings Cached
1
+ # Rails Settings Cached
2
2
 
3
3
  This a plugin that makes managing a table of
4
4
  а global key, value pairs easy. Think of it like a global Hash stored in your database,
@@ -6,39 +6,23 @@ that uses simple ActiveRecord like methods for manipulation. Keep track of any g
6
6
  setting that you don't want to hard code into your rails app. You can store any kind
7
7
  of object. Strings, numbers, arrays, or any object.
8
8
 
9
- > 🚨 BREAK CHANGES WARNING:
10
- > rails-settings-cached 2.x has redesigned the API, the new version will compatible with the stored setting values by an older version.
11
- > When you want to upgrade 2.x, you must read the README again, and follow guides to change your Setting model.
12
- > 0.x stable branch: https://github.com/huacnlee/rails-settings-cached/tree/0.x
9
+ [![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![CI Status](https://travis-ci.org/huacnlee/rails-settings-cached.svg)](http://travis-ci.org/huacnlee/rails-settings-cached) [![codecov.io](https://codecov.io/github/huacnlee/rails-settings-cached/coverage.svg?branch=master)](https://codecov.io/github/huacnlee/rails-settings-cached?branch=master)
13
10
 
14
- ## Status
15
-
16
- [![Gem Version](https://badge.fury.io/rb/rails-settings-cached.svg)](https://rubygems.org/gems/rails-settings-cached) [![CI Status](https://travis-ci.org/huacnlee/rails-settings-cached.svg)](http://travis-ci.org/huacnlee/rails-settings-cached) [![Code Climate](https://codeclimate.com/github/huacnlee/rails-settings-cached/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/rails-settings-cached) [![codecov.io](https://codecov.io/github/huacnlee/rails-settings-cached/coverage.svg?branch=master)](https://codecov.io/github/huacnlee/rails-settings-cached?branch=master)
17
-
18
- ## Setup
11
+ ## Installation
19
12
 
20
13
  Edit your Gemfile:
21
14
 
22
- ```ruby
23
- gem "rails-settings-cached", "~> 2.0"
24
- ```
25
-
26
- Generate your settings:
27
-
28
15
  ```bash
29
- $ rails g settings:install
16
+ $ bundle add rails-settings-cached
30
17
  ```
31
18
 
32
- If you want custom model name:
19
+ Generate your settings:
33
20
 
34
21
  ```bash
35
22
  $ rails g settings:install
36
- ```
37
-
38
- Or use a custom name:
39
23
 
40
- ```bash
41
- $ rails g settings:install SiteConfig
24
+ # Or use a custom name:
25
+ $ rails g settings:install AppConfig
42
26
  ```
43
27
 
44
28
  You will get `app/models/setting.rb`
@@ -46,20 +30,26 @@ You will get `app/models/setting.rb`
46
30
  ```rb
47
31
  class Setting < RailsSettings::Base
48
32
  # cache_prefix { "v1" }
49
-
33
+ field :app_name, default: "Rails Settings Cache Demo"
50
34
  field :host, default: "http://example.com"
35
+ field :default_locale, default: "zh-CN"
51
36
  field :readonly_item, type: :integer, default: 100, readonly: true
52
37
  field :user_limits, type: :integer, default: 20
53
38
  field :exchange_rate, type: :float, default: 0.123
54
39
  field :admin_emails, type: :array, default: %w[admin@rubyonrails.org]
40
+ field :captcha_enable, type: :boolean, default: true
41
+
55
42
  # Override array separator, default: /[\n,]/ split with \n or comma.
56
43
  field :tips, type: :array, separator: /[\n]+/
57
- field :captcha_enable, type: :boolean, default: 1
44
+
58
45
  field :notification_options, type: :hash, default: {
59
46
  send_all: true,
60
47
  logging: true,
61
48
  sender_email: "foo@bar.com"
62
49
  }
50
+
51
+ # lambda default value
52
+ field :welcome_message, type: :string, default: -> { "welcome to #{self.app_name}" }
63
53
  end
64
54
  ```
65
55
 
@@ -68,12 +58,12 @@ You must use `field` method to statement the setting keys, otherwise you can't u
68
58
  Now just put that migration in the database with:
69
59
 
70
60
  ```bash
71
- rake db:migrate
61
+ $ rails db:migrate
72
62
  ```
73
63
 
74
64
  ## Usage
75
65
 
76
- The syntax is easy. First, let's create some settings to keep track of:
66
+ The syntax is easy. First, let's create some settings to keep track of:
77
67
 
78
68
  ```ruby
79
69
  irb > Setting.host
@@ -201,7 +191,7 @@ config/routes.rb
201
191
 
202
192
  ```rb
203
193
  namespace :admin do
204
- resources :settings
194
+ resource :settings
205
195
  end
206
196
  ```
207
197
 
@@ -257,78 +247,50 @@ app/views/admin/settings/show.html.erb
257
247
  Use YAML format to config the SMTP_html
258
248
  </div>
259
249
  </div>
260
- <% end %>
261
- ```
262
-
263
- ## Backward compatible to support 0.x scoped settings
264
-
265
- You may used the scoped setting feature in 0.x version. Before you upgrade rails-settings-cached 2.x, you must follow this guide to backward compatible it.
266
-
267
- For example:
268
250
 
269
- ```rb
270
- class User < ApplicationRecord
271
- include RailsSettings::Extend
272
- end
273
-
274
- @user.settings.color = "red"
275
- @user.settings.foo = 123
251
+ <div>
252
+ <%= f.submit 'Update Settings' %>
253
+ </div>
254
+ <% end %>
276
255
  ```
277
256
 
278
- create `app/models/concerns/scoped_setting.rb`
257
+ ## Scoped Settings
279
258
 
280
- ```rb
281
- module ScopedSetting
282
- extend ActiveSupport::Concern
259
+ > 🚨 BREAK CHANGES WARNING:
260
+ > rails-settings-cached 2.x has redesigned the API, the new version will compatible with the stored setting values by an older version.
261
+ > When you want to upgrade 2.x, you must read the README again, and follow guides to change your Setting model.
262
+ > 0.x stable branch: https://github.com/huacnlee/rails-settings-cached/tree/0.x
283
263
 
284
- included do
285
- has_many :settings, as: :thing
286
- end
264
+ - [Backward compatible to support 0.x scoped settings](docs/backward-compatible-to-scoped-settings.md)
287
265
 
288
- class_methods do
289
- def scoped_field(name, default: nil)
290
- define_method(name) do
291
- obj = settings.where(var: name).take || settings.new(var: name, value: default)
292
- obj.value
293
- end
266
+ For new project / new user of rails-settings-cached. The [ActiveRecord::AttributeMethods::Serialization](https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html#method-i-serialize) is best choice.
294
267
 
295
- define_method("#{name}=") do |val|
296
- record = settings.where(var: name).take || settings.new(var: name)
297
- record.value = val
298
- record.save!
268
+ > This is reason of why rails-settings-cached 2.x removed **Scoped Settings** feature.
299
269
 
300
- val
301
- end
302
- end
303
- end
304
- end
305
- ```
270
+ For example:
306
271
 
307
- Now include it for your model:
272
+ We wants a preferences setting for user.
308
273
 
309
274
  ```rb
310
- class User < ApplicationRecord
311
- include ScopedSetting
312
-
313
- scoped_field :color, default: ""
314
- scoped_field :foo, default: 0
275
+ class User < ActiveRecord::Base
276
+ serialize :preferences
315
277
  end
316
- ```
317
-
318
- Now you must to find project with ".setting." for replace with:
319
-
320
- Same values will fetch from the `settings` table.
321
278
 
322
- ```rb
323
- @user.color = "red"
324
- @user.color # => "red"
325
- @user.foo = 123
326
- @user.foo # =>
279
+ @user = User.new
280
+ @user.preferences[:receive_emails] = true
281
+ @user.preferences[:public_email] = true
282
+ @user.save
327
283
  ```
328
284
 
329
285
  ## Use cases:
330
286
 
331
- - [ruby-china/homeland](https://github.com/ruby-china/homeland)
332
- - [thebluedoc/bluedoc](https://github.com/thebluedoc/bluedoc/blob/master/app/models/setting.rb)
333
- - [tootsuite/mastodon](https://github.com/tootsuite/mastodon)
334
- - [helpyio/helpy](https://github.com/helpyio/helpy)
287
+ - [ruby-china/homeland](https://github.com/ruby-china/homeland) - master
288
+ - [forem/forem](https://github.com/forem/forem) - 2.x
289
+ - [siwapp/siwapp](https://github.com/siwapp/siwapp) - 2.x
290
+ - [aidewoode/black_candy](https://github.com/aidewoode/black_candy) - 2.x
291
+ - [thebluedoc/bluedoc](https://github.com/thebluedoc/bluedoc/blob/master/app/models/setting.rb) - 2.x
292
+ - [tootsuite/mastodon](https://github.com/tootsuite/mastodon) - 0.6.x
293
+ - [helpyio/helpy](https://github.com/helpyio/helpy) - 0.5.x
294
+
295
+
296
+ And more than [1K repositories](https://github.com/huacnlee/rails-settings-cached/network/dependents) used.
@@ -3,14 +3,15 @@
3
3
  require "rails/generators"
4
4
  require "rails/generators/migration"
5
5
 
6
- module Settings
6
+ module RailsSettings
7
7
  class InstallGenerator < Rails::Generators::NamedBase
8
+ namespace "settings:install"
8
9
  desc "Generate RailsSettings files."
9
10
  include Rails::Generators::Migration
10
11
 
11
12
  argument :name, type: :string, default: "setting"
12
13
 
13
- source_root File.expand_path("../templates", __FILE__)
14
+ source_root File.expand_path("templates", __dir__)
14
15
 
15
16
  @@migrations = false
16
17
 
@@ -3,7 +3,7 @@
3
3
  module RailsSettings
4
4
  class << self
5
5
  def version
6
- "2.2.0"
6
+ "2.2.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.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-29 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -130,9 +130,10 @@ files:
130
130
  - lib/rails-settings/railtie.rb
131
131
  - lib/rails-settings/version.rb
132
132
  homepage: https://github.com/huacnlee/rails-settings-cached
133
- licenses: []
133
+ licenses:
134
+ - MIT
134
135
  metadata: {}
135
- post_install_message:
136
+ post_install_message:
136
137
  rdoc_options: []
137
138
  require_paths:
138
139
  - lib
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  requirements: []
150
151
  rubygems_version: 3.0.3
151
- signing_key:
152
+ signing_key:
152
153
  specification_version: 4
153
154
  summary: Settings plugin for Rails that makes managing a table of global keys.
154
155
  test_files: []