From ae823439609af69688780e8e5967e03449dc4cd7 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 6 Aug 2019 13:30:31 -0700 Subject: [PATCH] allow configuration of comfy model base class --- app/models/comfy/cms/categorization.rb | 2 +- app/models/comfy/cms/category.rb | 2 +- app/models/comfy/cms/file.rb | 2 +- app/models/comfy/cms/fragment.rb | 2 +- app/models/comfy/cms/layout.rb | 2 +- app/models/comfy/cms/page.rb | 2 +- app/models/comfy/cms/revision.rb | 2 +- app/models/comfy/cms/site.rb | 2 +- app/models/comfy/cms/snippet.rb | 2 +- app/models/comfy/cms/translation.rb | 2 +- config/initializers/comfortable_mexican_sofa.rb | 3 +++ lib/comfortable_mexican_sofa/configuration.rb | 5 +++++ test/lib/configuration_test.rb | 1 + 13 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/models/comfy/cms/categorization.rb b/app/models/comfy/cms/categorization.rb index bd08e7394..57f19d1fe 100644 --- a/app/models/comfy/cms/categorization.rb +++ b/app/models/comfy/cms/categorization.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Categorization < ActiveRecord::Base +class Comfy::Cms::Categorization < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_categorizations" diff --git a/app/models/comfy/cms/category.rb b/app/models/comfy/cms/category.rb index 5acc7d47b..7443ede72 100644 --- a/app/models/comfy/cms/category.rb +++ b/app/models/comfy/cms/category.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Category < ActiveRecord::Base +class Comfy::Cms::Category < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_categories" diff --git a/app/models/comfy/cms/file.rb b/app/models/comfy/cms/file.rb index e8bb3a673..e1b5bb51a 100644 --- a/app/models/comfy/cms/file.rb +++ b/app/models/comfy/cms/file.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::File < ActiveRecord::Base +class Comfy::Cms::File < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_files" diff --git a/app/models/comfy/cms/fragment.rb b/app/models/comfy/cms/fragment.rb index 3d4d034dc..a941afb1e 100644 --- a/app/models/comfy/cms/fragment.rb +++ b/app/models/comfy/cms/fragment.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Fragment < ActiveRecord::Base +class Comfy::Cms::Fragment < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_fragments" diff --git a/app/models/comfy/cms/layout.rb b/app/models/comfy/cms/layout.rb index c4447032a..747f91a38 100644 --- a/app/models/comfy/cms/layout.rb +++ b/app/models/comfy/cms/layout.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Layout < ActiveRecord::Base +class Comfy::Cms::Layout < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_layouts" diff --git a/app/models/comfy/cms/page.rb b/app/models/comfy/cms/page.rb index 932319410..fa593d392 100644 --- a/app/models/comfy/cms/page.rb +++ b/app/models/comfy/cms/page.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Page < ActiveRecord::Base +class Comfy::Cms::Page < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_pages" diff --git a/app/models/comfy/cms/revision.rb b/app/models/comfy/cms/revision.rb index 0a155661c..806c2e161 100644 --- a/app/models/comfy/cms/revision.rb +++ b/app/models/comfy/cms/revision.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Revision < ActiveRecord::Base +class Comfy::Cms::Revision < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_revisions" diff --git a/app/models/comfy/cms/site.rb b/app/models/comfy/cms/site.rb index da11b396d..923745968 100644 --- a/app/models/comfy/cms/site.rb +++ b/app/models/comfy/cms/site.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Site < ActiveRecord::Base +class Comfy::Cms::Site < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_sites" diff --git a/app/models/comfy/cms/snippet.rb b/app/models/comfy/cms/snippet.rb index 2d33f1e56..e1d699ebe 100644 --- a/app/models/comfy/cms/snippet.rb +++ b/app/models/comfy/cms/snippet.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Snippet < ActiveRecord::Base +class Comfy::Cms::Snippet < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_snippets" diff --git a/app/models/comfy/cms/translation.rb b/app/models/comfy/cms/translation.rb index 276ab9fcd..9de763aaa 100644 --- a/app/models/comfy/cms/translation.rb +++ b/app/models/comfy/cms/translation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Comfy::Cms::Translation < ActiveRecord::Base +class Comfy::Cms::Translation < ComfortableMexicanSofa.config.base_model.to_s.constantize self.table_name = "comfy_cms_translations" diff --git a/config/initializers/comfortable_mexican_sofa.rb b/config/initializers/comfortable_mexican_sofa.rb index 71c6ea87c..4ac8e3758 100644 --- a/config/initializers/comfortable_mexican_sofa.rb +++ b/config/initializers/comfortable_mexican_sofa.rb @@ -10,6 +10,9 @@ # Controller that Comfy::Cms::BaseController will inherit from # config.public_base_controller = 'ApplicationController' + # Model that Comfy models will inherit from + # config.base_model = 'ActiveRecord::Base' + # Module responsible for authentication. You can replace it with your own. # It simply needs to have #authenticate method. See http_auth.rb for reference. # config.admin_auth = 'ComfyAdminAuthentication' diff --git a/lib/comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb index b548099d7..474ba9f0a 100644 --- a/lib/comfortable_mexican_sofa/configuration.rb +++ b/lib/comfortable_mexican_sofa/configuration.rb @@ -9,6 +9,10 @@ class ComfortableMexicanSofa::Configuration # 'ApplicationController' is the default attr_accessor :admin_base_controller + # Model that Comfy models will inherit from + # 'ApplicationRecord' is the default + attr_accessor :base_model + # Controller that Comfy::Cms::BaseController will inherit from # 'ApplicationController' is the default attr_accessor :public_base_controller @@ -90,6 +94,7 @@ def initialize @cms_title = "ComfortableMexicanSofa CMS Engine" @admin_base_controller = "ApplicationController" @public_base_controller = "ApplicationController" + @base_model = "ActiveRecord::Base" @admin_auth = "ComfortableMexicanSofa::AccessControl::AdminAuthentication" @admin_authorization = "ComfortableMexicanSofa::AccessControl::AdminAuthorization" @public_auth = "ComfortableMexicanSofa::AccessControl::PublicAuthentication" diff --git a/test/lib/configuration_test.rb b/test/lib/configuration_test.rb index add836305..e0cbecb4f 100644 --- a/test/lib/configuration_test.rb +++ b/test/lib/configuration_test.rb @@ -9,6 +9,7 @@ def test_configuration_presence assert_equal "ComfortableMexicanSofa CMS Engine", config.cms_title assert_equal "ApplicationController", config.admin_base_controller assert_equal "ApplicationController", config.public_base_controller + assert_equal "ActiveRecord::Base", config.base_model assert_equal "ComfortableMexicanSofa::AccessControl::AdminAuthentication", config.admin_auth assert_equal "ComfortableMexicanSofa::AccessControl::AdminAuthorization", config.admin_authorization assert_equal "ComfortableMexicanSofa::AccessControl::PublicAuthentication", config.public_auth