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

Version Path
kriss-gettext_i18n-0.2.0 vendor/globalize2/lib/globalize/model/active_record.rb
kriss-gettext_i18n-0.2.1 vendor/globalize2/lib/globalize/model/active_record.rb
kriss-gettext_i18n-0.2.2 vendor/globalize2/lib/globalize/model/active_record.rb
kriss-gettext_i18n-0.2.3 vendor/globalize2/lib/globalize/model/active_record.rb
simonmenke-globalize2-0.0.1 lib/globalize/model/active_record.rb