Sha256: 5e6de7057b3b5f975a7f42810f53481d63874ca7fd6f197a1edf0191e223c740

Contents?: true

Size: 882 Bytes

Versions: 2

Compression:

Stored size: 882 Bytes

Contents

module Lit
  class Localization < ActiveRecord::Base

    ## SCOPES
    scope :changed, where(:is_changed=>true)

    ## ASSOCIATIONS
    belongs_to :locale
    belongs_to :localization_key

    ## VALIDATIONS
    validates :locale_id,
              :presence=>true

    ## ACCESSIBLE
    attr_accessible :translated_value, :locale_id

    ## BEFORE & AFTER
    before_update :update_is_changed
    after_update :mark_localization_key_completed

    def to_s
      self.value
    end

    def full_key
      "#{self.locale.locale}.#{self.localization_key.localization_key}"
    end

    def get_value
      is_changed? ? self.translated_value : self.default_value
    end

    private
      def update_is_changed
        self.is_changed = true unless is_changed?
      end

      def mark_localization_key_completed
        self.localization_key.mark_completed!
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lit-0.0.3.1 app/models/lit/localization.rb
lit-0.0.3 app/models/lit/localization.rb