Module: BuddyTranslatable
- Defined in:
- lib/buddy_translatable.rb,
lib/buddy_translatable/core.rb,
lib/buddy_translatable/version.rb
Defined Under Namespace
Modules: Core
Constant Summary collapse
- VERSION =
'1.1.0'
Class Method Summary collapse
- .included(base) ⇒ Object
- .parse_translatable_data(data) ⇒ Object
- .translatable_attr_json?(model_class, attr) ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/buddy_translatable.rb', line 6 def self.included(base) base.extend BuddyTranslatable::Core end |
.parse_translatable_data(data) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/buddy_translatable.rb', line 10 def self.parse_translatable_data(data) res = data || {} res = {} unless res.present? res = JSON.parse(res) if res.is_a?(String) res.symbolize_keys end |
.translatable_attr_json?(model_class, attr) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/buddy_translatable.rb', line 17 def self.translatable_attr_json?(model_class, attr) migrated = ActiveRecord::Base.connection.tables.include?(model_class.table_name) return :text unless migrated columns_data = model_class.try(:column_types) || model_class.try(:attribute_types) format = (columns_data[attr.to_s].type rescue :text) # rubocop:disable Style/RescueModifier %i[string text].exclude?(format) end |