Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow configuration of comfy model base class #887

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/comfy/cms/categorization.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/category.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/file.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/fragment.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/layout.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/page.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/revision.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/site.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/snippet.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion app/models/comfy/cms/translation.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
3 changes: 3 additions & 0 deletions config/initializers/comfortable_mexican_sofa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions lib/comfortable_mexican_sofa/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/lib/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down