rails-settings-cached 2.7.0 → 2.7.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 +4 -4
- data/README.md +9 -4
- data/lib/rails-settings/base.rb +9 -2
- data/lib/rails-settings/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 70c3d68c88fbd1a2a3cc1e9f78a45e06fc7b7a6df4698137e2a4ea6c77a27e33
         | 
| 4 | 
            +
              data.tar.gz: fd6ecee62edad7a5ca942fbe7e102ae6e3f075ea471e120dcc5a5f1d5f3fdb33
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
| 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 | 
            -
              } | 
| 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  | 
| 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
         | 
    
        data/lib/rails-settings/base.rb
    CHANGED
    
    | @@ -37,9 +37,16 @@ module RailsSettings | |
| 37 37 | 
             
                    _define_field(key, **opts)
         | 
| 38 38 | 
             
                  end
         | 
| 39 39 |  | 
| 40 | 
            -
                   | 
| 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 |  | 
    
        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. | 
| 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- | 
| 11 | 
            +
            date: 2021-07-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |