Sha256: c824b9bede6e33e9ba3379d30456bcba6bd3c175a88f0f111b1b1dc042ec7864

Contents?: true

Size: 818 Bytes

Versions: 2

Compression:

Stored size: 818 Bytes

Contents

require 'active_record'
require 'ruby2ruby'
require 'parse_tree'
require 'parse_tree_extensions'

class Translation < ActiveRecord::Base
  
  attr_protected :proc
  serialize :value
  
  named_scope :locale, lambda {|locale|
    { :conditions => {:locale => locale }}
  }
  
  named_scope :key, lambda { |key|
    { :conditions => {:key => key} }
  }
  
  named_scope :keys, lambda { |key, separator|
    separator ||= I18n.default_separator
    { :conditions => "key LIKE '#{key}#{separator}%'" }
  }
  
  def value=(v)
    case v
      when Proc
        write_attribute(:value, v.to_ruby)
        write_attribute(:proc, true)
      else
        write_attribute(:value, v)
    end
  end
  
  def value
    if proc
      Kernel.eval read_attribute( :value )
    else
      read_attribute( :value )
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
theoooo-i18n-0.2.0 lib/i18n/backend/active_record/translation.rb
theoooo-i18n-0.2.1 lib/i18n/backend/active_record/translation.rb