From 22e6aab1abbf2a18539ef0ac298a950d57a97f1e Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 17:41:13 +0500 Subject: [PATCH 1/9] fix a race between snapshot rebuild and invalidation --- app/models/activeadmin_settings/setting.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/activeadmin_settings/setting.rb b/app/models/activeadmin_settings/setting.rb index 584d9f4..5b7c223 100644 --- a/app/models/activeadmin_settings/setting.rb +++ b/app/models/activeadmin_settings/setting.rb @@ -83,7 +83,7 @@ def value(name, locale = nil) end def reset_snapshot - @snapshot = nil + @snapshot_lock.synchronize { @snapshot = nil } end private @@ -99,8 +99,9 @@ def snapshot_values current = @snapshot return current.values if fresh?(current, ttl) - @snapshot = Snapshot.new(load_values, monotonic_now) - @snapshot.values + snapshot = Snapshot.new(load_values, monotonic_now) + @snapshot = snapshot + snapshot.values end end From f66564810559c03a0ca3dc7a66485bd766dcc7bd Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 18:17:39 +0500 Subject: [PATCH 2/9] serve a stale snapshot while another thread rebuilds it --- app/models/activeadmin_settings/setting.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/activeadmin_settings/setting.rb b/app/models/activeadmin_settings/setting.rb index 5b7c223..1453f7b 100644 --- a/app/models/activeadmin_settings/setting.rb +++ b/app/models/activeadmin_settings/setting.rb @@ -95,13 +95,21 @@ def snapshot_values current = @snapshot return current.values if fresh?(current, ttl) - @snapshot_lock.synchronize do + unless @snapshot_lock.try_lock + return current.values if current + + @snapshot_lock.lock + end + + begin current = @snapshot return current.values if fresh?(current, ttl) snapshot = Snapshot.new(load_values, monotonic_now) @snapshot = snapshot snapshot.values + ensure + @snapshot_lock.unlock end end From bc18c12c41ef174bdb4d9ecf35d7e6e733a9058e Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 18:17:39 +0500 Subject: [PATCH 3/9] build the snapshot from an unscoped relation --- app/models/activeadmin_settings/setting.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/activeadmin_settings/setting.rb b/app/models/activeadmin_settings/setting.rb index 1453f7b..9426bcf 100644 --- a/app/models/activeadmin_settings/setting.rb +++ b/app/models/activeadmin_settings/setting.rb @@ -119,8 +119,8 @@ def fresh?(snapshot, ttl) def load_values values = {} - all.each do |setting| - values[[setting.name, setting.locale.to_s]] = setting.value.freeze + unscoped.each do |setting| + values[[setting.name.to_s, setting.locale.to_s]] = setting.value.freeze rescue StandardError next end @@ -132,4 +132,4 @@ def monotonic_now end end end -end \ No newline at end of file +end From 51bd1296b6723c2fe31e525cb80127c8281bba89 Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 18:11:36 +0500 Subject: [PATCH 4/9] memoize the settings config instead of re-reading yaml on every call --- lib/activeadmin-settings.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/activeadmin-settings.rb b/lib/activeadmin-settings.rb index 748bc6b..a72d263 100644 --- a/lib/activeadmin-settings.rb +++ b/lib/activeadmin-settings.rb @@ -24,22 +24,22 @@ module ActiveadminSettings # Load configuration from config/activeadmin_settings.yml def self.load_config - config_file = ::Rails.root.join(@@config_file) - @load_config = {} - - if File.exist?(config_file) - data = YAML::load(ERB.new(IO.read(config_file)).result) - @load_config = data if data + @load_config ||= begin + config_file = ::Rails.root.join(@@config_file) + data = YAML::load(ERB.new(IO.read(config_file)).result) if File.exist?(config_file) + data || {} end - @load_config end def self.all_settings - @all_settings = {} - load_config.each do |key, settings| - @all_settings.merge!(settings) + @all_settings ||= load_config.each_with_object({}) do |(_key, settings), all| + all.merge!(settings) end - @all_settings + end + + def self.reload_config! + @load_config = nil + @all_settings = nil end def self.groups From 3e929cf9b37d9b0a43744bd1de4d4e41f71fd7a4 Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 17:26:23 +0500 Subject: [PATCH 5/9] replace render :text and update_attributes, removed in rails 5.1 and 6 --- .../activeadmin_settings/admin_users_controller.rb | 8 ++++---- .../activeadmin_settings/settings_controller.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/activeadmin_settings/admin_users_controller.rb b/app/controllers/activeadmin_settings/admin_users_controller.rb index 94ca60f..5f4dba2 100644 --- a/app/controllers/activeadmin_settings/admin_users_controller.rb +++ b/app/controllers/activeadmin_settings/admin_users_controller.rb @@ -3,10 +3,10 @@ class ActiveadminSettings::AdminUsersController < ApplicationController def update @object = AdminUser.find(params[:id]) - if @object.update_attributes(permitted_params[:admin_user]) - render :text => "ok" + if @object.update(permitted_params[:admin_user]) + render :plain => "ok" else - render :text => @object.errors.to_json, :status => :unprocessable_entity + render :plain => @object.errors.to_json, :status => :unprocessable_entity end end @@ -15,7 +15,7 @@ def create if @object.save render :partial => "admin/settings/admin", :locals => {:admin => @object}, :layout => false else - render :text => @object.errors.to_json, :status => :unprocessable_entity + render :plain => @object.errors.to_json, :status => :unprocessable_entity end end diff --git a/app/controllers/activeadmin_settings/settings_controller.rb b/app/controllers/activeadmin_settings/settings_controller.rb index c7464b7..76e609d 100644 --- a/app/controllers/activeadmin_settings/settings_controller.rb +++ b/app/controllers/activeadmin_settings/settings_controller.rb @@ -4,9 +4,9 @@ class ActiveadminSettings::SettingsController < ApplicationController def update @object = ActiveadminSettings::Setting.find(params[:id]) if @object.update(permitted_params[:setting]) - render :text => @object.value + render :plain => @object.value else - render :text => "error" + render :plain => "error" end end From 0dc5b6fe207be8a6114af28939fd9dcf69f7a99b Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 16:50:14 +0500 Subject: [PATCH 6/9] keep plain settings on a single-line input --- app/views/admin/settings/_settings_table.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/settings/_settings_table.html.erb b/app/views/admin/settings/_settings_table.html.erb index 84ae6d7..65b2bda 100644 --- a/app/views/admin/settings/_settings_table.html.erb +++ b/app/views/admin/settings/_settings_table.html.erb @@ -54,7 +54,7 @@ :as => :text, :input_html => { :class => "settings-redactor" } %> <% else %> - <%= f.input :string, :placeholder => "#{t '.default' }: " + setting.default_value(locale) %> + <%= f.input :string, :as => :string, :placeholder => "#{t '.default' }: " + setting.default_value(locale) %> <% end %> <% end %> <% end %> From e95cfb8a3531b46d04456578e3f7bbfa9f8b82e0 Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 18:17:47 +0500 Subject: [PATCH 7/9] drop unused runtime dependencies --- README.md | 7 ------- activeadmin-settings.gemspec | 5 +---- lib/activeadmin-settings/version.rb | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3ccdb89..ab06450 100644 --- a/README.md +++ b/README.md @@ -28,13 +28,6 @@ Add i18n configuration to `config/application.rb` file: #### ActiveRecord - gem "aws-s3" - gem "fog" - gem "mini_magick" - gem "carrierwave" - - gem "bson_ext" - gem "devise" gem "activeadmin-settings" Run migrations: diff --git a/activeadmin-settings.gemspec b/activeadmin-settings.gemspec index 53981e4..511fb8a 100644 --- a/activeadmin-settings.gemspec +++ b/activeadmin-settings.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |gem| gem.version = ActiveadminSettings::VERSION gem.authors = ["Alex Kravets"] gem.email = ["santyor@gmail.com"] - gem.homepage = "https://github.com/slate-studio/activeadmin-settings" + gem.homepage = "https://github.com/Yarroo/activeadmin-settings" gem.description = "Easy to use general purpose settings backend for activeadmin" gem.summary = "" @@ -15,8 +15,5 @@ Gem::Specification.new do |gem| gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) - gem.add_dependency "mini_magick", ">= 3.4" - gem.add_dependency "carrierwave", ">= 1.0" - gem.add_dependency "devise", ">= 4.0" gem.add_dependency "activeadmin", ">= 2.0" end diff --git a/lib/activeadmin-settings/version.rb b/lib/activeadmin-settings/version.rb index 8210324..9693be2 100644 --- a/lib/activeadmin-settings/version.rb +++ b/lib/activeadmin-settings/version.rb @@ -1,3 +1,3 @@ module ActiveadminSettings - VERSION = "0.5.0" + VERSION = "0.6.0" end From a57bbf5bf6e59e568cc40848fb97bb340b2e229b Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 18:11:36 +0500 Subject: [PATCH 8/9] drop mongoid instructions, this fork is activerecord only --- README.md | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/README.md b/README.md index ab06450..d090d56 100644 --- a/README.md +++ b/README.md @@ -26,54 +26,11 @@ Add i18n configuration to `config/application.rb` file: config.i18n.default_locale = :en config.i18n.available_locales = [:en, :ru] -#### ActiveRecord - - gem "activeadmin-settings" - Run migrations: $ rake activeadmin_settings:install:migrations $ rake db:migrate -#### Mongoid 2.x - -If you're using mongoid 2.x the gem expects to see **activeadmin-mongoid** and **carrierwave-mongoid** (for image uploading feature) in Gemfile. Here is a working example: - - gem "aws-s3" - gem "fog" - gem "mini_magick" - gem "carrierwave-mongoid" - - gem "bson_ext" - gem "mongoid" - gem "mongoid-globalize" - gem "devise" - gem "activeadmin-mongoid" - gem "activeadmin-settings" - -#### Mongoid 3.x - -Here is an example of Gemfile with a support of 3.x version: - - # Mongoid 3.x - gem 'moped', git: 'git://github.com/mongoid/moped.git' - gem 'mongoid', '~> 3.0.5' - - # Assets - gem 'aws-s3' - gem 'fog' - gem 'mini_magick' - gem 'carrierwave-mongoid', git: 'git://github.com/jnicklas/carrierwave-mongoid.git', - branch: 'mongoid-3.0', - require: 'carrierwave/mongoid' - - # Activeadmin - gem 'devise', '>= 2.1.2' - gem 'activeadmin-mongoid', git: 'git://github.com/elia/activeadmin-mongoid.git' - gem "mongoid-globalize" - gem 'activeadmin-settings' - - ### Configuration After installation you should find a new **Settings** menu in the admin. If no configuration found in `config/activeadmin_settings.yml` only *Admins* tab is shown. *Admin* tab implements basic functionality of editing *AdminUser* objects. From 609c5d859abc76982b231433c66da609f2efdd69 Mon Sep 17 00:00:00 2001 From: Vershinin Sergey Date: Mon, 24 Aug 2026 16:50:14 +0500 Subject: [PATCH 9/9] point homepage and readme images at this repository --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d090d56..04606d7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This gem is not supported and developed anymore. Easy to use general purpose settings backend for activeadmin. -![ActiveadminSettings Demo](https://raw.github.com/slate-studio/activeadmin-settings/master/img/activeadmin-settings-demo.jpg) +![ActiveadminSettings Demo](https://raw.githubusercontent.com/Yarroo/activeadmin-settings/master/img/activeadmin-settings-demo.jpg) ### Installation @@ -67,7 +67,7 @@ All of the settings may be cplitted to groupes by adding optional param `group`, As result we'll see: -![ActiveadminSettings Group Example](https://raw.github.com/slate-studio/activeadmin-settings/master/img/activeadmin-group-example.png) +![ActiveadminSettings Group Example](https://raw.githubusercontent.com/Yarroo/activeadmin-settings/master/img/activeadmin-group-example.png) There are a few types of settings: