Module: Mongoid::Association::Nested::Buildable

Included in:
Many, One
Defined in:
lib/mongoid/association/nested/nested_buildable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#associationObject

Returns the value of attribute association



6
7
8
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 6

def association
  @association
end

#attributesObject

Returns the value of attribute attributes



6
7
8
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 6

def attributes
  @attributes
end

#existingObject

Returns the value of attribute existing



6
7
8
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 6

def existing
  @existing
end

#optionsObject

Returns the value of attribute options



6
7
8
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 6

def options
  @options
end

Instance Method Details

#allow_destroy?true, false

Determines if destroys are allowed for this document.

Examples:

Do we allow a destroy?

builder.allow_destroy?

Returns:

  • (true, false)

    True if the allow destroy option was set.

Since:

  • 2.0.0.rc.1



16
17
18
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 16

def allow_destroy?
  options[:allow_destroy] || false
end

#convert_id(klass, id) ⇒ BSON::ObjectId, ...

Convert an id to its appropriate type.

Examples:

Convert the id.

builder.convert_id(Person, "4d371b444835d98b8b000010")

Parameters:

  • klass (Class)

    The class we're trying to convert for.

  • id (String)

    The id, usually coming from the form.

Returns:

Since:

  • 2.0.0.rc.6



66
67
68
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 66

def convert_id(klass, id)
  klass.using_object_ids? ? BSON::ObjectId.mongoize(id) : id
end

#reject?(document, attrs) ⇒ true, false

Returns the reject if option defined with the macro.

Examples:

Is there a reject proc?

builder.reject?

Parameters:

  • document (Document)

    The parent document of the relation

  • attrs (Hash)

    The attributes to check for rejection.

Returns:

  • (true, false)

    True and call proc or method if rejectable, false if not.

Since:

  • 2.0.0.rc.1



31
32
33
34
35
36
37
38
39
40
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 31

def reject?(document, attrs)
  case callback = options[:reject_if]
    when Symbol
      document.method(callback).arity == 0 ? document.send(callback) : document.send(callback, attrs)
    when Proc
      callback.call(attrs)
    else
      false
  end
end

#update_only?true, false

Determines if only updates can occur. Only valid for one-to-one relations.

Examples:

Is this update only?

builder.update_only?

Returns:

  • (true, false)

    True if the update_only option was set.

Since:

  • 2.0.0.rc.1



51
52
53
# File 'lib/mongoid/association/nested/nested_buildable.rb', line 51

def update_only?
  options[:update_only] || false
end