Class: Mongoid::Relations::NestedBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid/relations/nested_builder.rb

Overview

This is the superclass for builders that are in charge of handling creation, deletion, and updates of documents through that ever so lovely #accepts_nested_attributes_for.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/mongoid/relations/nested_builder.rb', line 9

def attributes
  @attributes
end

#existingObject

Returns the value of attribute existing.



9
10
11
# File 'lib/mongoid/relations/nested_builder.rb', line 9

def existing
  @existing
end

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/mongoid/relations/nested_builder.rb', line 9

def 
  @metadata
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/mongoid/relations/nested_builder.rb', line 9

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



19
20
21
# File 'lib/mongoid/relations/nested_builder.rb', line 19

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

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

TODO:

Durran: Move this into a common reusable place.

Convert an id to its appropriate type.

Examples:

Convert the id.

builder.convert_id("4d371b444835d98b8b000010")

Parameters:

  • id (String)

    The id, usually coming from the form.

Returns:

Since:

  • 2.0.0.rc.6



63
64
65
# File 'lib/mongoid/relations/nested_builder.rb', line 63

def convert_id(id)
  .constraint.convert(id)
end

#reject?(attrs) ⇒ true, false

Returns the reject if option defined with the macro.

Examples:

Is there a reject proc?

builder.reject?

Parameters:

  • attrs (Hash)

    The attributes to check for rejection.

Returns:

  • (true, false)

    True and call proc if rejectable, false if not.

Since:

  • 2.0.0.rc.1



33
34
35
36
# File 'lib/mongoid/relations/nested_builder.rb', line 33

def reject?(attrs)
  criteria = options[:reject_if]
  criteria ? criteria.call(attrs) : false
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



47
48
49
# File 'lib/mongoid/relations/nested_builder.rb', line 47

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