From 327f92e10fc64e564d665c23b5793a92ff433335 Mon Sep 17 00:00:00 2001 From: Denny de la Haye <2021@denny.me> Date: Wed, 2 Jun 2021 02:03:58 +0100 Subject: [PATCH] Get rid of top-level method definitions, to appease new rubocop warning --- .../ShinyCMS/config/initializers/assets.rb | 46 ++++++++++--------- plugins/ShinyCMS/config/routes/tools.rb | 12 ++--- plugins/ShinyCMS/db/seeds/capabilities.rb | 17 +++---- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/plugins/ShinyCMS/config/initializers/assets.rb b/plugins/ShinyCMS/config/initializers/assets.rb index 8b9a8b5f5..d710e0c9a 100644 --- a/plugins/ShinyCMS/config/initializers/assets.rb +++ b/plugins/ShinyCMS/config/initializers/assets.rb @@ -13,34 +13,36 @@ Rails.application.config.assets.paths << ShinyCMS::Engine.root.join( 'app/assets/javascript' ) # Add theme images and stylesheets to the asset load path -def add_all_themes_to_asset_load_path - available_themes.each do |theme_name| - add_theme_to_asset_load_path( theme_name ) +class ShinyCMS::ThemeAssetsSetup + def add_all_themes_to_asset_load_path + available_themes.each do |theme_name| + add_theme_to_asset_load_path( theme_name ) + end end -end -def available_themes - Dir[ 'themes/*' ].collect { |name| name.sub( 'themes/', '' ) } -end + def available_themes + Dir[ 'themes/*' ].collect { |name| name.sub( 'themes/', '' ) } + end -def add_theme_to_asset_load_path( theme_name ) - add_theme_images_to_asset_load_path( theme_name ) - add_theme_styles_to_asset_load_path( theme_name ) -end + def add_theme_to_asset_load_path( theme_name ) + add_theme_images_to_asset_load_path( theme_name ) + add_theme_styles_to_asset_load_path( theme_name ) + end -def add_theme_images_to_asset_load_path( theme_name ) - images_dir = Rails.root.join "themes/#{theme_name}/images" - return unless Dir.exist? images_dir + def add_theme_images_to_asset_load_path( theme_name ) + images_dir = Rails.root.join "themes/#{theme_name}/images" + return unless Dir.exist? images_dir - Rails.application.config.assets.paths << images_dir -end + Rails.application.config.assets.paths << images_dir + end -def add_theme_styles_to_asset_load_path( theme_name ) - stylesheets_dir = Rails.root.join "themes/#{theme_name}/stylesheets" - return unless Dir.exist? stylesheets_dir + def add_theme_styles_to_asset_load_path( theme_name ) + stylesheets_dir = Rails.root.join "themes/#{theme_name}/stylesheets" + return unless Dir.exist? stylesheets_dir - Rails.application.config.assets.paths << stylesheets_dir - Rails.application.config.assets.precompile += %W[ #{theme_name}.css ] + Rails.application.config.assets.paths << stylesheets_dir + Rails.application.config.assets.precompile += %W[ #{theme_name}.css ] + end end -add_all_themes_to_asset_load_path +ShinyCMS::ThemeAssetsSetup.new.add_all_themes_to_asset_load_path diff --git a/plugins/ShinyCMS/config/routes/tools.rb b/plugins/ShinyCMS/config/routes/tools.rb index 08bf8a59a..6f47c6b13 100644 --- a/plugins/ShinyCMS/config/routes/tools.rb +++ b/plugins/ShinyCMS/config/routes/tools.rb @@ -21,11 +21,9 @@ mount LetterOpenerWeb::Engine, at: '/dev/tools/outbox' if Rails.env.development? # Sidekiq Web provides a web dashboard for Sidekiq jobs and queues -def sidekiq_web_enabled? - ENV['DISABLE_SIDEKIQ_WEB']&.downcase != 'true' -end +sidekiq_web_enabled = ( ENV['DISABLE_SIDEKIQ_WEB']&.downcase != 'true' ) -if sidekiq_web_enabled? +if sidekiq_web_enabled require 'sidekiq/web' require 'sidekiq-status/web' @@ -35,11 +33,9 @@ def sidekiq_web_enabled? end # Coverband provides a web UI for viewing code usage information -def coverband_web_ui_enabled? - ENV['DISABLE_COVERBAND_WEB_UI']&.downcase != 'true' -end +coverband_web_ui_enabled = ( ENV['DISABLE_COVERBAND_WEB_UI']&.downcase != 'true' ) -if coverband_web_ui_enabled? +if coverband_web_ui_enabled authenticate :user, ->( user ) { user.can? :use_coverband, :tools } do mount Coverband::Reporters::Web.new, at: '/admin/tools/coverband', as: :coverband unless Rails.env.test? end diff --git a/plugins/ShinyCMS/db/seeds/capabilities.rb b/plugins/ShinyCMS/db/seeds/capabilities.rb index 8a53a7053..53a85ad05 100644 --- a/plugins/ShinyCMS/db/seeds/capabilities.rb +++ b/plugins/ShinyCMS/db/seeds/capabilities.rb @@ -16,18 +16,19 @@ seeder.seed_standard_admin_capabilities( category: :admin_users ) # Most of the capabilities to be set here are not the standard four, so ... - -def add_capabilities( capability_data ) - capability_data.each_key do |category_name| - category = ShinyCMS::CapabilityCategory.find_or_create_by!( name: category_name ) - - capability_data[ category_name ].each do |capability_name| - category.capabilities.find_or_create_by( name: capability_name ) +class ShinyCMS::CapabilitySetup + def add( capability_data ) + capability_data.each_key do |category_name| + category = ShinyCMS::CapabilityCategory.find_or_create_by!( name: category_name ) + + capability_data[ category_name ].each do |capability_name| + category.capabilities.find_or_create_by( name: capability_name ) + end end end end -add_capabilities( +ShinyCMS::CapabilitySetup.new.add( { general: %w[ view_admin_area view_admin_toolbar ], tools: %w[ use_blazer use_coverband use_letter_opener_web use_rails_email_preview use_sidekiq_web ],