Sha256: 63e09b9e0ffc022695ff8fe369161b7db31163a35e68e5bbf6875d20b5981ca6
Contents?: true
Size: 1.11 KB
Versions: 5
Compression:
Stored size: 1.11 KB
Contents
require 'globalize/translation' require 'globalize/locale/fallbacks' require 'globalize/model/active_record/adapter' require 'globalize/model/active_record/translated' module Globalize module Model module ActiveRecord class << self def create_proxy_class(klass) Object.const_set "#{klass.name}Translation", Class.new(::ActiveRecord::Base){ belongs_to "#{klass.name.underscore}".intern def locale read_attribute(:locale).to_sym end def locale=(locale) write_attribute(:locale, locale.to_s) end } end def define_accessors(klass, attr_names) attr_names.each do |attr_name| klass.send :define_method, attr_name, lambda { globalize.fetch self.class.locale, attr_name } klass.send :define_method, "#{attr_name}=", lambda {|val| globalize.stash self.class.locale, attr_name, val self[attr_name] = val } end end end end end end
Version data entries
5 entries across 5 versions & 2 rubygems