This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/lib/orbit_model/language_restrict.rb

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