module ActiveMongoid::Associations::DocumentRelation::Accessors::ClassMethods

Private Instance Methods

document_getter(name, metadata) click to toggle source

Getters

# File lib/active_mongoid/associations/document_relation/accessors.rb, line 57
def document_getter(name, metadata)
  self.instance_eval do
    define_method(name) do |reload = false|
      get_document_relation(name, metadata, nil, reload)
    end
  end
end
document_id_getter(name, metadata) click to toggle source
# File lib/active_mongoid/associations/document_relation/accessors.rb, line 65
def document_id_getter(name, metadata)
  self.instance_eval do
    define_method("#{name}_id") do
      attribute = read_attribute("#{name}_id")
      attribute.nil? ? nil : ::ActiveMongoid::BSON::ObjectId.from_string(attribute)
    end
  end
end
document_id_setter(name, metadata) click to toggle source
# File lib/active_mongoid/associations/document_relation/accessors.rb, line 86
def document_id_setter(name, metadata)
  self.instance_eval do
    define_method("#{name}_id=") do |bson_id|
      attribute = bson_id.nil? ? nil : bson_id.to_s
      write_attribute("#{name}_id", attribute)
    end
  end
end
document_setter(name, metadata) click to toggle source
# File lib/active_mongoid/associations/document_relation/accessors.rb, line 74
def document_setter(name, metadata)
  self.instance_eval do
    define_method("#{name}=") do |object|
      if value = get_document_relation(name, metadata, object)
        set_document_relation(name, value.substitute(object))
      else
        build_document(name, object, metadata)
      end
    end
  end
end
existence_check(name) click to toggle source
# File lib/active_mongoid/associations/document_relation/accessors.rb, line 45
          def existence_check(name)
            module_eval <<-END
              def #{name}?
                !__send__(:#{name}).blank?
              end
              alias :has_#{name}? :#{name}?
            END
            self
          end