123456789101112131415161718192021222324252627282930313233343536373839404142 |
- require 'json_with_indifferent_access'
- module JSONSerializedField
- extend ActiveSupport::Concern
- module ClassMethods
- def json_serialize(*fields)
- fields.each do |field|
- class_eval <<-CODE
- serialize :
- validate :
- def
- @
- case input
- when String
- if input.strip.length == 0
- self[:
- else
- json = JSON.parse(input) rescue nil
- if json
- self[:
- else
- @
- end
- end
- when Hash
- self[:
- else
- @
- end
- end
- def
- errors.add(:
- end
- CODE
- end
- end
- end
- end
|