module MongoidNestedFields::NestedFieldSetter
Public Class Methods
included(reciever)
click to toggle source
# File lib/mongoid_nested_fields/nested_field_setter.rb, line 65 def self.included(reciever) reciever::ClassMethods.send :include, ClassMethods end
Private Instance Methods
_nested_fields()
click to toggle source
# File lib/mongoid_nested_fields/nested_field_setter.rb, line 71 def _nested_fields self.class.instance_variable_get(:@_nested_fields) end
_nested_fields_must_be_valid()
click to toggle source
# File lib/mongoid_nested_fields/nested_field_setter.rb, line 97 def _nested_fields_must_be_valid _nested_fields.each do |field| value = read_attribute(field) i = 0 field_errors = {} value.each do |v| if v.respond_to?(:invalid?) and v.invalid? field_errors[i.to_s] = v.errors i += 1 end end if value.respond_to? :each errors.add(field, field_errors) unless field_errors.empty? end unless _nested_fields.nil? end
_restore_nested_fields()
click to toggle source
# File lib/mongoid_nested_fields/nested_field_setter.rb, line 86 def _restore_nested_fields _nested_fields.each do |nested_field| restored_nested_field = [] value = read_attribute(nested_field) value.each do |part| restored_nested_field << (part.respond_to?(:origin) ? part.origin : part) end unless value.nil? write_attribute(nested_field, restored_nested_field) end end
_serialize_nested_fields()
click to toggle source
# File lib/mongoid_nested_fields/nested_field_setter.rb, line 75 def _serialize_nested_fields _nested_fields.each do |nested_field| serialized_nested_field = [] value = read_attribute(nested_field) value.each do |part| serialized_nested_field << (part.respond_to?(:to_mongo) ? part.to_mongo : part) end unless value.nil? write_attribute(nested_field, serialized_nested_field) end end