Class: FromClauseTranslate::TranslationData
- Inherits:
-
Object
- Object
- FromClauseTranslate::TranslationData
- Defined in:
- lib/from_clause_translate/translation_data.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#plurals ⇒ Object
readonly
Returns the value of attribute plurals.
-
#selections ⇒ Object
readonly
Returns the value of attribute selections.
-
#translated ⇒ Object
readonly
Returns the value of attribute translated.
Instance Method Summary collapse
- #add_column(column) ⇒ Object
- #add_columns(columns) ⇒ Object
- #add_plural(plural) ⇒ Object
-
#initialize(model) ⇒ TranslationData
constructor
A new instance of TranslationData.
- #translates?(column) ⇒ Boolean
Constructor Details
#initialize(model) ⇒ TranslationData
Returns a new instance of TranslationData.
6 7 8 9 10 11 |
# File 'lib/from_clause_translate/translation_data.rb', line 6 def initialize(model) @model = model @translated = {} @plurals = {} @selections = I18n.available_locales.map { |locale| [locale, {}] }.to_h end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/from_clause_translate/translation_data.rb', line 4 def model @model end |
#plurals ⇒ Object (readonly)
Returns the value of attribute plurals.
4 5 6 |
# File 'lib/from_clause_translate/translation_data.rb', line 4 def plurals @plurals end |
#selections ⇒ Object (readonly)
Returns the value of attribute selections.
4 5 6 |
# File 'lib/from_clause_translate/translation_data.rb', line 4 def selections @selections end |
#translated ⇒ Object (readonly)
Returns the value of attribute translated.
4 5 6 |
# File 'lib/from_clause_translate/translation_data.rb', line 4 def translated @translated end |
Instance Method Details
#add_column(column) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/from_clause_translate/translation_data.rb', line 21 def add_column(column) hash = column.is_a?(Hash) ? column : {name: column} return if translates?(hash[:name]) || !model.column_names.include?("#{hash[:name]}_#{I18n.locale}") column = hash[:name] translated[column] = true define_translated_selection column, hash column = column.to_s dashed = "#{column}_" define_translated_column_getter_and_setter column, dashed define_translated_column_changing_methods column, dashed end |
#add_columns(columns) ⇒ Object
17 18 19 |
# File 'lib/from_clause_translate/translation_data.rb', line 17 def add_columns(columns) columns.each(&method(:add_column)) end |
#add_plural(plural) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/from_clause_translate/translation_data.rb', line 38 def add_plural(plural) plural = plural.to_sym translated[plural] = true column = plural.to_s.singularize.to_sym selection = I18n.available_locales.map do |locale| "#{model.quoted_table_name}.\"#{column}_#{locale}\"" end.join ',' plurals[plural] = selection I18n.available_locales.each do |locale| selections[locale][plural] = selection end end |
#translates?(column) ⇒ Boolean
13 14 15 |
# File 'lib/from_clause_translate/translation_data.rb', line 13 def translates?(column) @translated[column.to_sym] || false end |