activeadmin_settings_cached 2.2.0 → 3.0.0

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
- SHA1:
3
- metadata.gz: 603aca9e3f4f9203e5615d4d1a6de0971c712bd0
4
- data.tar.gz: 9479bedf926819b92387a229c3a86f82d0bc47d3
2
+ SHA256:
3
+ metadata.gz: ee6c14de48fbbb2c5b92865102c9e924b0653fa9e000c8c16cc60a7b44e857e1
4
+ data.tar.gz: b5a1e74381075692da0aec927cf76a8205c3d26c0964f297a6909652da735008
5
5
  SHA512:
6
- metadata.gz: 93838c32f20dffc07cd5089f91b5c95587286b078ca8769b0768b55c40d90c36b22b332edcb6c58805a6fd6bf58bb4504e58b5bfcecf49c1f1faa644255ad17b
7
- data.tar.gz: 2c7b7968c14440954dce41f50b02ac8b3f2e2ef787e02512212a6c2df7fb9fc38d56928b4ad17c39726037e9e6dde55a849191edc1d863667500ffbb1f53560e
6
+ metadata.gz: 9ead2b850cf382b950cbe026055405f75a55071a86834b1caafeeb17ce9f52549538c987a32a33a13592ee96e6b448b4b2ef65137544f487e47aee71c205d0c5
7
+ data.tar.gz: dd196049e5aafa3611f7636bf3b56ea9e089c7fb1c4b29600f24fd0cef8bf99d25c9623f923b8decf9ca7da2a5da385e8645bf19e4629c7e97ee037037138207
data/.github/stale.yml ADDED
@@ -0,0 +1,17 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 60
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: wontfix
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This issue has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby: ['3.2', '3.3', '3.4']
15
+ gemfile: [rails7.2, rails8.0]
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true
24
+ - name: Create test app
25
+ run: bundle exec rake setup
26
+ - name: Run specs
27
+ run: bundle exec rake
data/Appraisals CHANGED
@@ -1,17 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'rails4.2' do
4
- gem 'rails', '~> 4.2.0'
3
+ appraise 'rails7.2' do
4
+ gem 'rails', '~> 7.2.0'
5
5
  end
6
6
 
7
- appraise 'rails5.0' do
8
- gem 'rails', '~> 5.0.1'
9
- gem 'inherited_resources', git: 'https://github.com/activeadmin/inherited_resources.git'
10
- gem 'listen'
11
- end
12
-
13
- appraise 'rails5.1' do
14
- gem 'rails', '~> 5.1.0'
15
- gem 'inherited_resources', git: 'https://github.com/activeadmin/inherited_resources.git'
16
- gem 'listen'
7
+ appraise 'rails8.0' do
8
+ gem 'rails', '~> 8.0.0'
17
9
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # v3.0.0 2026-10-31
2
+
3
+ ## Changed
4
+
5
+ - Support rails-settings-cached v2 (`>= 2.8.2`), drop support for older versions
6
+ - Show editable fields grouped by scope, input depends on field type
7
+ - Values are coerced by rails-settings-cached, `Coercions` is removed
8
+ - Save only changed values
9
+ - Show validation errors in flash
10
+ - Test against Rails 7.2 and 8.0 on GitHub Actions, remove Travis CI
11
+
12
+ ## Removed
13
+
14
+ - `starting_with` and `key` options, use `scope` option instead
15
+
16
+ # v2.3.1 2018-05-22
17
+
18
+ ## Changed
19
+
20
+ - Remove dry-types dependency
21
+
22
+ ## Fixed
23
+ - Breaking change in dry-types: Rename Types::Form to Types::Params (Julien FLAJOLLET)
24
+
1
25
  # v2.2.0 2017-12-22
2
26
 
3
27
  ## Added
data/Dockerfile CHANGED
@@ -1,6 +1,4 @@
1
- FROM ruby:2.3-slim
2
-
3
- ENV PHANTOMJS_VERSION 1.9.8
1
+ FROM ruby:3.4-slim
4
2
 
5
3
  RUN apt-get update -qq && \
6
4
  DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
@@ -8,19 +6,8 @@ RUN apt-get update -qq && \
8
6
  gcc \
9
7
  g++ \
10
8
  libsqlite3-dev \
11
- git-core \
12
- wget \
13
- libfreetype6 \
14
- libfontconfig \
15
- bzip2 && \
9
+ libyaml-dev \
10
+ git-core && \
16
11
  apt-get clean
17
12
 
18
- RUN \
19
- wget -q --no-check-certificate -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && \
20
- mkdir -p /srv/var && \
21
- tar -xjf /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C /tmp && \
22
- rm -f /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 && \
23
- mv /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/ /srv/var/phantomjs && \
24
- ln -s /srv/var/phantomjs/bin/phantomjs /usr/bin/phantomjs
25
-
26
13
  WORKDIR /app
data/Gemfile CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ gem 'rails', '~> 8.0.0'
6
+ gem 'sassc-rails'
7
+ gem 'sprockets-rails'
8
+
5
9
  group :test do
6
10
  gem 'pry-byebug'
7
- gem 'therubyracer'
11
+ gem 'puma'
8
12
  end
9
13
 
10
14
  gemspec
data/Makefile CHANGED
@@ -1,7 +1,10 @@
1
+ RUN := run --rm --service-ports
2
+ DOCKER_COMPOSE_RUN := docker-compose $(RUN)
3
+
1
4
  default: test
2
5
 
3
- rake:
4
- bundle exec rake ${T}
6
+ bash:
7
+ ${DOCKER_COMPOSE_RUN} app bash
5
8
 
6
9
  test: appraisals
7
10
  bundle exec appraisal rspec ${T}
@@ -9,9 +12,17 @@ test: appraisals
9
12
  appraisals: setup
10
13
  bundle exec appraisal install
11
14
 
15
+ appraisals-generate:
16
+ bundle exec appraisal generate
17
+
18
+
12
19
  setup:
13
- gem install bundler --no-ri --no-rdoc
20
+ gem install bundler
14
21
  bundle check || bundle install -j 2
22
+ bundle exec appraisal rake setup
23
+
24
+ down:
25
+ docker-compose down
15
26
 
16
27
  clean:
17
28
  rm -f Gemfile.lock
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Activeadmin Settings Cached
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/activeadmin_settings_cached.svg)](http://badge.fury.io/rb/activeadmin_settings_cached)
4
- [![Build Status](https://travis-ci.org/artofhuman/activeadmin_settings_cached.svg?branch=master)](https://travis-ci.org/artofhuman/activeadmin_settings_cached)
5
- [![Dependency Status](https://gemnasium.com/badges/github.com/artofhuman/activeadmin_settings_cached.svg)](https://gemnasium.com/github.com/artofhuman/activeadmin_settings_cached)
6
- [![Coverage Status](https://coveralls.io/repos/github/artofhuman/activeadmin_settings_cached/badge.svg?branch=master)](https://coveralls.io/github/artofhuman/activeadmin_settings_cached?branch=master)
4
+ [![CI](https://github.com/artofhuman/activeadmin_settings_cached/actions/workflows/ci.yml/badge.svg)](https://github.com/artofhuman/activeadmin_settings_cached/actions/workflows/ci.yml)
7
5
 
8
6
  Provides a nice UI interface for [rails-settings-cached](https://github.com/huacnlee/rails-settings-cached) gem in [Active Admin](http://activeadmin.info/).
9
7
 
8
+ Version 3 supports rails-settings-cached v2 (`>= 2.8.2`). For rails-settings-cached `< 0.6.7` use version 2.x of this gem.
9
+
10
10
  ## Installation
11
11
 
12
12
  Add this line to your application's Gemfile:
@@ -26,9 +26,9 @@ Create your settings model:
26
26
 
27
27
  Create your settings page:
28
28
 
29
- # From generators
30
- $ rails g active_admin:settings Setting
31
-
29
+ # From generators
30
+ $ rails g active_admin:settings Setting
31
+
32
32
  # Or manual
33
33
 
34
34
  ``` ruby
@@ -43,15 +43,38 @@ ActiveAdmin.register_page 'Setting' do
43
43
  end
44
44
  ```
45
45
 
46
- And configure your default values in your Settings model:
46
+ And define your fields in your Setting model:
47
47
 
48
48
  ``` ruby
49
- class Settings < RailsSettings::CachedSettings
50
- defaults[:my_awesome_settings] = 'This is my settings'
49
+ class Setting < RailsSettings::Base
50
+ field :app_name, default: 'My app'
51
+
52
+ scope :mail do
53
+ field :admin_emails, type: :array, default: %w[admin@example.com]
54
+ field :notifications_enabled, type: :boolean, default: true
55
+ field :default_locale, default: 'en', option_values: %w[en de ru], help_text: 'Language of emails'
56
+ end
57
+
58
+ field :api_key, default: ENV['API_KEY'], readonly: true
51
59
  end
52
60
  ```
53
61
 
54
- In your application's admin interface, there will now be a new page with this setting
62
+ In your application's admin interface, there will now be a new page with these settings.
63
+
64
+ Every editable field is shown. Readonly fields are not shown. Fields are grouped by `scope`.
65
+ The input depends on the field `type`:
66
+
67
+ Type | Input
68
+ ---------------------------------- | -----
69
+ `:string` | text field
70
+ `:integer`, `:float`, `:big_decimal` | number field
71
+ `:boolean` | checkbox
72
+ `:array` | textarea, one value per line
73
+ `:hash` | textarea with YAML
74
+
75
+ A field with `option_values` is shown as a select. A field with `help_text` shows it as a hint.
76
+ Validation errors from `validates` are shown in the flash message.
77
+ Only changed values are saved, so unchanged fields keep their default value.
55
78
 
56
79
  ## active_admin_settings_page DSL
57
80
 
@@ -68,14 +91,20 @@ end
68
91
  Tool | Description
69
92
  --------------------- | -----------
70
93
  :model_name |String, settings model name override (default: uses name from global config.)
71
- :starting_with |String, each key must starting with, (default: nil)
72
- :key |String, Symbol root key, can be replacement for starting_with, (default: nil)
94
+ :scope |Symbol, Array of Symbols, show only fields from these scopes (default: nil, all fields)
73
95
  :template |String, custom template rendering (default: 'admin/settings/index')
74
96
  :template_object |object passing to view (default: ActiveadminSettingsCached::Model instance)
75
97
  :display |Hash, display settings override (default: {})
76
98
  :title |String, title value override (default: I18n.t('settings.menu.label'))
77
99
  :after_save |Proc, callback for action after POST request, (default: nil)
78
-
100
+
101
+ #### Settings on different pages
102
+
103
+ ```ruby
104
+ ActiveAdmin.register_page 'Mail Settings' do
105
+ active_admin_settings_page(scope: :mail, title: 'Mail Settings')
106
+ end
107
+ ```
79
108
 
80
109
  ## Localization
81
110
  You can localize settings keys in local file
@@ -84,7 +113,9 @@ You can localize settings keys in local file
84
113
  en:
85
114
  settings:
86
115
  attributes:
87
- my_awesome_settings: 'My Awesome Lolaized Setting'
116
+ my_awesome_settings: 'My Awesome Localized Setting'
117
+ scopes:
118
+ mail: 'Mail'
88
119
  ```
89
120
  ## Model name
90
121
 
@@ -98,7 +129,7 @@ end
98
129
 
99
130
  ## Display options
100
131
 
101
- If you need define display options for settings fields, eg textarea, url or :timestamp and etc., you can set `display` option in initializer.
132
+ If you need to override the input for a field, eg textarea, url or :timestamp and etc., you can set `display` option in initializer.
102
133
 
103
134
 
104
135
  ``` ruby
@@ -120,3 +151,18 @@ Available options see [here](https://github.com/justinfrench/formtastic#the-avai
120
151
  3. Commit your changes (`git commit -am 'Add some feature'`)
121
152
  4. Push to the branch (`git push origin my-new-feature`)
122
153
  5. Create new Pull Request
154
+
155
+ ## How run local example
156
+
157
+ ```
158
+ make bash
159
+ make setup
160
+ cd spec/rails/rails-8.0.*/
161
+ BUNDLE_GEMFILE=/app/gemfiles/rails8.0.gemfile bundle exec rails s -b 0.0.0.0
162
+ ```
163
+
164
+ ## Upgrading from 2.x
165
+
166
+ - Update rails-settings-cached to v2 and define your settings with `field`.
167
+ - `starting_with` and `key` options are removed. Use rails-settings-cached `scope` and the `scope` option.
168
+ - Values are coerced by rails-settings-cached field types. `display` only changes the input.
@@ -19,18 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
20
  s.require_paths = ['lib']
21
21
 
22
- s.add_dependency 'activeadmin'
23
- s.add_dependency 'dry-types', '>= 0.8.1'
24
- s.add_dependency 'rails-settings-cached', '>= 0.5.3', '< 0.6.7'
22
+ s.add_dependency 'activeadmin', '>= 1.0', '< 4'
23
+ s.add_dependency 'rails-settings-cached', '~> 2.8', '>= 2.8.2'
25
24
 
26
25
  s.add_development_dependency 'appraisal'
27
26
  s.add_development_dependency 'bundler'
28
27
  s.add_development_dependency 'capybara'
29
- s.add_development_dependency 'coveralls'
30
- s.add_development_dependency 'database_cleaner'
31
- s.add_development_dependency 'poltergeist'
28
+ s.add_development_dependency 'database_cleaner-active_record'
32
29
  s.add_development_dependency 'rake'
33
30
  s.add_development_dependency 'rspec-rails'
34
- s.add_development_dependency 'selenium-webdriver'
35
31
  s.add_development_dependency 'sqlite3'
36
32
  end
@@ -7,19 +7,26 @@
7
7
  <th><%= t('settings.index.value')%></th>
8
8
  </tr>
9
9
  </thead>
10
- <tbody>
11
- <% settings_model.settings.each_pair do |name, _| %>
12
- <% field_name = settings_model.field_name(name) %>
13
- <tr class="odd">
14
- <td><strong><%= f.label field_name, t("settings.attributes.#{field_name}", default: field_name) %></strong></td>
15
- <td>
16
- <div class='form'>
17
- <ol><%= f.input field_name, settings_model.field_options(field_name, name) %></ol>
18
- </div>
19
- </td>
20
- </tr>
21
- <% end%>
22
- </tbody>
10
+ <% settings_model.fields_by_scope.each_pair do |scope, fields| %>
11
+ <tbody>
12
+ <% if scope %>
13
+ <tr>
14
+ <th colspan="2"><%= t("settings.scopes.#{scope}", default: scope.to_s.humanize) %></th>
15
+ </tr>
16
+ <% end %>
17
+ <% fields.each do |field| %>
18
+ <% key = field[:key] %>
19
+ <tr class="odd">
20
+ <td><strong><%= f.label key, t("settings.attributes.#{key}", default: key) %></strong></td>
21
+ <td>
22
+ <div class='form'>
23
+ <ol><%= f.input key, settings_model.field_options(key) %></ol>
24
+ </div>
25
+ </td>
26
+ </tr>
27
+ <% end %>
28
+ </tbody>
29
+ <% end %>
23
30
  </table>
24
31
  <%= f.submit %>
25
32
  <% end %>
@@ -3,6 +3,7 @@ de:
3
3
  settings:
4
4
  update:
5
5
  success: Konfiguration wurde gespeichert.
6
+ error: 'Konfiguration konnte nicht gespeichert werden: %{details}'
6
7
 
7
8
  activerecord:
8
9
  models:
@@ -3,6 +3,7 @@ en:
3
3
  settings:
4
4
  update:
5
5
  success: Settings was successfully updated.
6
+ error: 'Settings were not saved: %{details}'
6
7
 
7
8
  activerecord:
8
9
  models:
@@ -3,6 +3,7 @@ ru:
3
3
  settings:
4
4
  update:
5
5
  success: Настройки были успешно сохранены.
6
+ error: 'Не удалось сохранить настройки: %{details}'
6
7
 
7
8
  activerecord:
8
9
  models:
data/docker-compose.yml CHANGED
@@ -1,13 +1,17 @@
1
- version: '2'
1
+ version: '3.3'
2
2
 
3
3
  services:
4
4
  app:
5
5
  build: '.'
6
6
  command: 'make test'
7
7
  volumes:
8
- - '.:/app'
9
- - gems:/usr/local/bundle
8
+ - .:/app:cached
9
+ - bundler-data:/usr/local/bundle/
10
+ - bin-data:/usr/local/bin/
11
+ ports:
12
+ - "3000:3000"
13
+
10
14
 
11
15
  volumes:
12
- gems:
13
- external: true
16
+ bundler-data:
17
+ bin-data:
@@ -2,11 +2,13 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.2.0"
5
+ gem "rails", "~> 7.2.0"
6
+ gem "sassc-rails"
7
+ gem "sprockets-rails"
6
8
 
7
9
  group :test do
8
10
  gem "pry-byebug"
9
- gem "therubyracer"
11
+ gem "puma"
10
12
  end
11
13
 
12
14
  gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 8.0.0"
6
+ gem "sassc-rails"
7
+ gem "sprockets-rails"
8
+
9
+ group :test do
10
+ gem "pry-byebug"
11
+ gem "puma"
12
+ end
13
+
14
+ gemspec path: "../"
@@ -8,8 +8,7 @@ module ActiveadminSettingsCached
8
8
  #
9
9
  # @param [Hash] options
10
10
  # @option options [String] :model_name, settings model name override (default: uses name from global config.)
11
- # @option options [String] :starting_with, each key must starting with, (default: nil)
12
- # @option options [String] :key, root key can be replacement for starting_with, (default: nil)
11
+ # @option options [Symbol, Array<Symbol>] :scope, show only fields from these rails-settings-cached scopes (default: nil)
13
12
  # @option options [String] :template custom, template rendering (default: 'admin/settings/index')
14
13
  # @option options [String] :template_object, object to use in templates (default: ActiveadminSettingsCached::Model instance)
15
14
  # @option options [String] :display, display settings override (default: nil)
@@ -19,23 +18,32 @@ module ActiveadminSettingsCached
19
18
  options.assert_valid_keys(*ActiveadminSettingsCached::Options::VALID_OPTIONS)
20
19
 
21
20
  options = ActiveadminSettingsCached::Options.options_for(options)
22
- coercion =
23
- ActiveadminSettingsCached::Coercions.new(options[:template_object].defaults, options[:template_object].display)
24
21
 
25
22
  content title: options[:title] do
26
23
  render partial: options[:template], locals: { settings_model: options[:template_object] }
27
24
  end
28
25
 
29
26
  page_action :update, method: :post do
30
- settings_params = params.require(:settings).permit!
27
+ settings_model = options[:template_object]
28
+ settings_params = params.require(:settings).permit(*settings_model.keys)
29
+ errors = []
31
30
 
32
- coercion.cast_params(settings_params) do |name, value|
33
- options[:template_object].save(name, value)
31
+ settings_params.each do |key, value|
32
+ next unless settings_model.changed?(key, value)
33
+
34
+ settings_model.save(key, value)
35
+ rescue ActiveRecord::RecordInvalid => e
36
+ errors.concat(e.record.errors.full_messages)
37
+ end
38
+
39
+ if errors.any?
40
+ flash[:error] = t('activeadmin_settings_cached.settings.update.error', details: errors.join(', '))
41
+ else
42
+ flash[:success] = t('activeadmin_settings_cached.settings.update.success')
34
43
  end
35
44
 
36
- flash[:success] = t('activeadmin_settings_cached.settings.update.success'.freeze)
37
- Rails.version.to_i >= 5 ? redirect_back(fallback_location: admin_root_path) : redirect_to(:back)
38
45
  options[:after_save].call if options[:after_save].respond_to?(:call)
46
+ redirect_back(fallback_location: admin_root_path)
39
47
  end
40
48
 
41
49
  instance_eval(&block) if block_given?
@@ -5,9 +5,6 @@ require 'active_admin'
5
5
 
6
6
  module ActiveadminSettingsCached
7
7
  class Engine < Rails::Engine
8
- config.mount_at = '/'
9
- config.autoload_paths += Dir["#{config.root}/lib"]
10
-
11
8
  initializer 'activeadmin_settings_cached' do
12
9
  ::ActiveAdmin::DSL.send(:include, ::ActiveadminSettingsCached::DSL)
13
10
  end