Refactor globalize models code using a concern

I've chosen the name "Globalizable" because "Translatable" already
existed.
This commit is contained in:
Javi Martín
2018-10-11 02:29:08 +02:00
parent 3b5a12b0ab
commit 2ab49a1832
13 changed files with 20 additions and 24 deletions

View File

@@ -3,8 +3,7 @@ class AdminNotification < ActiveRecord::Base
translates :title, touch: true
translates :body, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
translation_class.instance_eval do
validates :title, presence: true

View File

@@ -5,8 +5,7 @@ class Banner < ActiveRecord::Base
translates :title, touch: true
translates :description, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
translation_class.instance_eval do
validates :title, presence: true, length: { minimum: 2 }

View File

@@ -8,8 +8,7 @@ class Budget
accepted_content_types: [ "application/pdf" ]
translates :title, :description, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
belongs_to :investment
belongs_to :status, class_name: 'Budget::Investment::Status'

View File

@@ -0,0 +1,8 @@
module Globalizable
extend ActiveSupport::Concern
included do
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
end
end

View File

@@ -9,8 +9,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
translates :body, touch: true
translates :body_html, touch: true
translates :toc_html, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy

View File

@@ -13,8 +13,7 @@ class Legislation::Process < ActiveRecord::Base
translates :summary, touch: true
translates :description, touch: true
translates :additional_info, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze

View File

@@ -4,8 +4,7 @@ class Legislation::Question < ActiveRecord::Base
include Notifiable
translates :title, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'

View File

@@ -3,8 +3,7 @@ class Legislation::QuestionOption < ActiveRecord::Base
include ActsAsParanoidAliases
translates :value, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question

View File

@@ -7,8 +7,7 @@ class Poll < ActiveRecord::Base
translates :name, touch: true
translates :summary, touch: true
translates :description, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
RECOUNT_DURATION = 1.week

View File

@@ -6,8 +6,7 @@ class Poll::Question < ActiveRecord::Base
include ActsAsParanoidAliases
translates :title, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
belongs_to :poll
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'

View File

@@ -4,8 +4,7 @@ class Poll::Question::Answer < ActiveRecord::Base
translates :title, touch: true
translates :description, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,

View File

@@ -4,8 +4,7 @@ class SiteCustomization::Page < ActiveRecord::Base
translates :title, touch: true
translates :subtitle, touch: true
translates :content, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
translation_class.instance_eval do
validates :title, presence: true

View File

@@ -8,8 +8,7 @@ class Widget::Card < ActiveRecord::Base
translates :title, touch: true
translates :description, touch: true
translates :link_text, touch: true
globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
include Globalizable
def self.header
where(header: true)