Sha256: 31bad4be5d1f1f2c23ef555a196671d68f6777ad2d4e8d0b0a2db73a5b8dab76

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

# This module is intended to be mixed into the ActiveRecord backend to allow
# storing Ruby Procs as translation values in the database.
#
#   I18n.backend = I18n::Backend::ActiveRecord.new
#   I18n::Backend::ActiveRecord::Translation.send(:include, I18n::Backend::ActiveRecord::StoreProcs)
#
# The StoreProcs module requires the ParseTree and ruby2ruby gems and therefor
# was extracted from the original backend.
#
# ParseTree is not compatible with Ruby 1.9.

begin
  require 'ruby2ruby'
  require 'parse_tree'
  require 'parse_tree_extensions'
rescue LoadError => e
  puts "can't use StoreProcs because: #{e.message}"
end

module I18n
  module Backend
    class ActiveRecord
      module StoreProcs
        def value=(v)
          case v
          when Proc
            write_attribute(:value, v.to_ruby)
            write_attribute(:is_proc, true)
          else
            write_attribute(:value, v)
          end
        end

        Translation.send(:include, self) if method(:to_s).respond_to?(:to_ruby)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
i18n-active_record-0.4.1 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.4.0 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.3.0 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.2.2 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.2.1 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.2.0 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.1.2 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.1.1 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.1.0 lib/i18n/backend/active_record/store_procs.rb
chipairon-i18n-active_record-0.0.4 lib/i18n/backend/active_record/store_procs.rb
chipairon-i18n-active_record-0.0.3 lib/i18n/backend/active_record/store_procs.rb
chipairon-i18n-active_record-0.0.2 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-backend-0.1.0 lib/i18n/backend/active_record/store_procs.rb
arena-i18n-active_record-0.0.4 lib/i18n/backend/active_record/store_procs.rb
arena-i18n-active_record-0.0.333 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.0.2 lib/i18n/backend/active_record/store_procs.rb
i18n-active_record-0.0.1 lib/i18n/backend/active_record/store_procs.rb