Class: Lit::Localization
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Lit::Localization
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_str ⇒ Object
27
28
29
|
# File 'app/models/lit/localization.rb', line 27
def full_key_str
@full_key_str
end
|
Instance Method Details
#changed ⇒ Object
7
|
# File 'app/models/lit/localization.rb', line 7
scope :changed, -> { where is_changed: true }
|
#full_key ⇒ Object
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_deleted ⇒ Object
21
|
# File 'app/models/lit/localization.rb', line 21
delegate :is_deleted, to: :localization_key
|
#last_change ⇒ Object
65
66
67
|
# File 'app/models/lit/localization.rb', line 65
def last_change
updated_at.to_s(:db)
end
|
#locale ⇒ Object
15
|
# File 'app/models/lit/localization.rb', line 15
belongs_to :locale, required: true
|
#locale_str ⇒ Object
61
62
63
|
# File 'app/models/lit/localization.rb', line 61
def locale_str
locale.locale
end
|
#localization_key_is_deleted ⇒ Object
57
58
59
|
# File 'app/models/lit/localization.rb', line 57
def localization_key_is_deleted
localization_key.is_deleted
end
|
#localization_key_str ⇒ Object
53
54
55
|
# File 'app/models/lit/localization.rb', line 53
def localization_key_str
localization_key.localization_key
end
|
#to_s ⇒ Object
37
38
39
|
# File 'app/models/lit/localization.rb', line 37
def to_s
translation
end
|
#translated_value_changed? ⇒ Object
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
|
#translation ⇒ Object
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
|
#value ⇒ Object
49
50
51
|
# File 'app/models/lit/localization.rb', line 49
def value
translation
end
|