Module: Sequel::Plugins::Translatable
- Defined in:
- lib/sequel/plugins/translatable.rb
Defined Under Namespace
Modules: ClassMethods, DatasetMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.configure(model, attributes = []) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sequel/plugins/translatable.rb', line 4 def self.configure(model, attributes = []) attributes = [*attributes] raise Error, "please specify attributes to use for translatable plugin" if attributes.empty? attributes.each do |attribute| model.class_eval <<-EOS, __FILE__, __LINE__ def #{attribute}=(value) send "#{attribute}_\#{base_locale}=", value end def #{attribute} send "#{attribute}_\#{base_locale}" end def #{attribute}_hash @#{attribute}_locales ||= columns.collect do |column| $1 if column=~/\\A#{Regexp.escape attribute}_(.+)\\z/ end.compact.sort.collect(&:to_sym) hash = {} @#{attribute}_locales.each do |locale| hash[locale] = send "#{attribute}_\#{locale}" end hash end EOS end end |