lib/i18n_column/base.rb in i18n_column-0.0.2 vs lib/i18n_column/base.rb in i18n_column-0.0.3

- old
+ new

@@ -16,23 +16,31 @@ # Creates i18n getter and setter methods for the given column names. def i18n_column(*col_names) for col_name in col_names class_eval <<-EOV def #{col_name} - json = #{col_name}_to_json + json = decode_#{col_name} json.nil? ? nil : json[::I18n.locale.to_s] end - + def #{col_name}=(value) - json = #{col_name}_to_json || {} + json = decode_#{col_name} || {} json[::I18n.locale.to_s] = value self[:#{col_name}] = json.to_json value end - + + def f#{col_name} + self.#{col_name} + end + + def f#{col_name}=(value) + self.#{col_name} = value + end + private - - def #{col_name}_to_json + + def decode_#{col_name} ::ActiveSupport::JSON::decode(self[:#{col_name}].to_s) || nil end EOV end end