31 lines
684 B
Ruby
31 lines
684 B
Ruby
module OrbitModel
|
|
|
|
module LanguageRestrict
|
|
|
|
def self.included(base)
|
|
base.class_eval do
|
|
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
|
before_save :update_available_language
|
|
send :include, InstanceMethods
|
|
end
|
|
end
|
|
|
|
module InstanceMethods
|
|
|
|
private
|
|
|
|
def update_available_language
|
|
VALID_LOCALES.each do |locale|
|
|
if (title_translations[locale].blank? rescue true)
|
|
self["available_for_#{locale}".to_sym] = false
|
|
else
|
|
self["available_for_#{locale}".to_sym] = true
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end |