Class: Lit::LocalizationKey
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lit::LocalizationKey
- Defined in:
- app/models/lit/localization_key.rb
Instance Attribute Summary collapse
-
#interpolated_key ⇒ Object
Returns the value of attribute interpolated_key.
Class Method Summary collapse
-
.default_search_options ⇒ Object
it can be overridden in parent application, for example: => “created_at desc”.
- .order_options ⇒ Object
- .search(options = {}) ⇒ Object
Instance Method Summary collapse
- #clone_localizations ⇒ Object
-
#completed ⇒ Object
SCOPES.
-
#localization_key ⇒ Object
ACCESSIBLE.
-
#localizations ⇒ Object
ASSOCIATIONS.
- #mark_all_completed! ⇒ Object
- #mark_completed ⇒ Object
- #mark_completed! ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#interpolated_key ⇒ Object
Returns the value of attribute interpolated_key.
3 4 5 |
# File 'app/models/lit/localization_key.rb', line 3 def interpolated_key @interpolated_key end |
Class Method Details
.default_search_options ⇒ Object
it can be overridden in parent application, for example: => “created_at desc”
64 65 66 |
# File 'app/models/lit/localization_key.rb', line 64 def self. {} end |
.order_options ⇒ Object
59 60 61 |
# File 'app/models/lit/localization_key.rb', line 59 def self. ['localization_key asc', 'localization_key desc', 'created_at asc', 'created_at desc', 'updated_at asc', 'updated_at desc'] end |
.search(options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/lit/localization_key.rb', line 68 def self.search( = {}) = .to_h.reverse_merge().with_indifferent_access s = self if [:order] && .include?([:order]) column, order = [:order].split(' ') s = s.order("#{Lit::LocalizationKey.quoted_table_name}.#{connection.quote_column_name(column)} #{order}") else s = s.ordered end localization_key_col = Lit::LocalizationKey.arel_table[:localization_key] default_value_col = Lit::Localization.arel_table[:default_value] translated_value_col = Lit::Localization.arel_table[:translated_value] if [:key_prefix].present? q = "#{options[:key_prefix]}%" s = s.where(localization_key_col.matches(q)) end if [:key].present? q = "%#{options[:key]}%" q_underscore = "%#{options[:key].parameterize.underscore}%" cond = localization_key_col.matches(q).or( default_value_col.matches(q).or( translated_value_col.matches(q) ) ).or(localization_key_col.matches(q_underscore)) s = s.joins([:localizations]).where(cond) end unless [:include_completed].to_i == 1 s = s.not_completed end s end |
Instance Method Details
#clone_localizations ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/lit/localization_key.rb', line 33 def clone_localizations new_created = false Lit::Locale.find_each do |locale| localizations.where(locale_id: locale.id).first_or_create do |l| l.default_value = interpolated_key new_created = true end end if new_created Lit::LocalizationKey.update_all ['is_completed=?', false], ['id=? and is_completed=?', id, false] end end |
#completed ⇒ Object
SCOPES
6 |
# File 'app/models/lit/localization_key.rb', line 6 scope :completed, proc { where(is_completed: true) } |
#localization_key ⇒ Object
ACCESSIBLE
20 21 22 |
# File 'app/models/lit/localization_key.rb', line 20 validates :localization_key, presence: true, uniqueness: { if: :localization_key_changed? } |
#localizations ⇒ Object
ASSOCIATIONS
17 |
# File 'app/models/lit/localization_key.rb', line 17 has_many :localizations, dependent: :destroy |
#mark_all_completed! ⇒ Object
54 55 56 57 |
# File 'app/models/lit/localization_key.rb', line 54 def mark_all_completed! localizations.update_all(['is_changed=?', true]) mark_completed! end |
#mark_completed ⇒ Object
46 47 48 |
# File 'app/models/lit/localization_key.rb', line 46 def mark_completed self.is_completed = localizations.changed.count(:id) == localizations.count end |
#mark_completed! ⇒ Object
50 51 52 |
# File 'app/models/lit/localization_key.rb', line 50 def mark_completed! save if mark_completed end |
#to_s ⇒ Object
29 30 31 |
# File 'app/models/lit/localization_key.rb', line 29 def to_s localization_key end |