Class: Lit::Localization

Inherits:
Base
  • Object
show all
Defined in:
app/models/lit/localization.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#retried_created, #retried_updated

Instance Method Summary collapse

Methods inherited from Base

#mark_for_retry, #rolledback_after_insert?, #rolledback_after_update?

Instance Attribute Details

#full_key_strObject

ACCESSORS



27
28
29
# File 'app/models/lit/localization.rb', line 27

def full_key_str
  @full_key_str
end

Instance Method Details

#changedObject

SCOPES



7
# File 'app/models/lit/localization.rb', line 7

scope :changed, -> { where is_changed: true }

#full_keyObject



41
42
43
# File 'app/models/lit/localization.rb', line 41

def full_key
  full_key_str || [locale.locale, localization_key.localization_key].join('.')
end

#is_deletedObject

DELEGATIONS



21
# File 'app/models/lit/localization.rb', line 21

delegate :is_deleted, to: :localization_key

#last_changeObject



65
66
67
# File 'app/models/lit/localization.rb', line 65

def last_change
  updated_at.to_s(:db)
end

#localeObject

VALIDATIONS



15
# File 'app/models/lit/localization.rb', line 15

belongs_to :locale, required: true

#locale_strObject



61
62
63
# File 'app/models/lit/localization.rb', line 61

def locale_str
  locale.locale
end

#localization_key_is_deletedObject



57
58
59
# File 'app/models/lit/localization.rb', line 57

def localization_key_is_deleted
  localization_key.is_deleted
end

#localization_key_strObject



53
54
55
# File 'app/models/lit/localization.rb', line 53

def localization_key_str
  localization_key.localization_key
end

#to_sObject



37
38
39
# File 'app/models/lit/localization.rb', line 37

def to_s
  translation
end

#translated_value_changed?Object

BEFORE & AFTER



32
33
34
# File 'app/models/lit/localization.rb', line 32

with_options if: :translated_value_changed? do |o|
  o.before_update :create_version
end

#translationObject



45
46
47
# File 'app/models/lit/localization.rb', line 45

def translation
  is_changed? && !translated_value.nil? ? translated_value : default_value
end

#update_default_value(value) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'app/models/lit/localization.rb', line 69

def update_default_value(value)
  return true if persisted? && default_value == value
  if persisted?
    update(default_value: value)
  else
    self.default_value = value
    save!
  end
end

#valueObject



49
50
51
# File 'app/models/lit/localization.rb', line 49

def value
  translation
end