Sha256: 05ab9da029deff92a79eb20d1c5daa7596fabd170aff05b5d29c8a3412d40dc8

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

module Lit
  class Localization < ActiveRecord::Base

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

    ## ASSOCIATIONS
    belongs_to :locale
    belongs_to :localization_key

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

    if ::Rails::VERSION::MAJOR<4
      ## ACCESSIBLE
      attr_accessible :translated_value, :locale_id
    end

    ## 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

4 entries across 4 versions & 1 rubygems

Version Path
lit-0.0.4.3 app/models/lit/localization.rb
lit-0.0.4.2 app/models/lit/localization.rb
lit-0.0.4.1 app/models/lit/localization.rb
lit-0.0.4 app/models/lit/localization.rb