Skip to content

Commit 435ba5f

Browse files
MONGOID-5570 Code Docs: Add missing documentation (#5559)
* Add missing documentation * Cleanup --------- Co-authored-by: Dmitry Rybakov <[email protected]>
1 parent 4381cfd commit 435ba5f

File tree

145 files changed

+1107
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1107
-84
lines changed

lib/mongoid.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
require "mongoid/warnings"
3232
require "mongoid/utils"
3333

34-
# If we are using Rails then we will include the Mongoid railtie. This has all
35-
# the nifty initializers that Mongoid needs.
34+
# If we are using Rails then we will include the Mongoid railtie.
35+
# This configures initializers required to integrate Mongoid with Rails.
3636
if defined?(Rails)
3737
require "mongoid/railtie"
3838
end
3939

40-
# add english load path by default
40+
# Add English locale config to load path by default.
4141
I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
4242

43+
# Top-level module for project.
4344
module Mongoid
4445
extend Forwardable
4546
extend Loggable
@@ -138,12 +139,16 @@ def storage_options
138139
#
139140
# @api private
140141
module GlobalDiscriminatorKeyAssignment
142+
141143
# This class is used for obtaining the method definition location for
142144
# Mongoid methods.
143145
class InvalidFieldHost
144146
include Mongoid::Document
145147
end
146148

149+
# Sets the global discriminator key name.
150+
#
151+
# @param [ String | Symbol ] value The new discriminator key name.
147152
def discriminator_key=(value)
148153
Mongoid::Fields::Validators::Macro.validate_field_name(InvalidFieldHost, value)
149154
value = value.to_s

lib/mongoid/association.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
require 'mongoid/association/eager_loadable'
2020

2121
module Mongoid
22+
23+
# Mixin module which adds association behavior to a Mongoid document.
24+
# Adds methods such as #embedded? which indicate a document's
25+
# relative association state.
2226
module Association
2327
extend ActiveSupport::Concern
2428
include Embedded::Cyclic

lib/mongoid/association/depending.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ module Depending
2020
end
2121

2222
class_methods do
23+
24+
# Returns all dependent association metadata objects.
25+
#
26+
# @return [ Array<Mongoid::Association::Relatable> ] The dependent
27+
# association metadata.
28+
#
2329
# @api private
2430
def _all_dependents
2531
superclass_dependents = superclass.respond_to?(:_all_dependents) ? superclass._all_dependents : []
@@ -62,6 +68,14 @@ def self.define_dependency!(association)
6268
end
6369
end
6470

71+
# Validates that an association's dependent strategy is
72+
# within the allowed enumeration.
73+
#
74+
# @param [ Mongoid::Association::Relatable ] association
75+
# The association to validate.
76+
#
77+
# @raises [ Mongoid::Errors::InvalidDependentStrategy ]
78+
# Error if invalid.
6579
def self.validate!(association)
6680
unless STRATEGIES.include?(association.dependent)
6781
raise Errors::InvalidDependentStrategy.new(association,

lib/mongoid/association/eager_loadable.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ module Association
99
# This module defines the eager loading behavior for criteria.
1010
module EagerLoadable
1111

12+
# Indicates whether the criteria has association
13+
# inclusions which should be eager loaded.
14+
#
15+
# @return [ true | false ] Whether to eager load.
1216
def eager_loadable?
1317
!criteria.inclusions.empty?
1418
end
1519

20+
# Load the associations for the given documents.
21+
#
22+
# @param [ Array<Mongoid::Document> ] docs The documents.
23+
#
24+
# @return [ Array<Mongoid::Document> ] The given documents.
1625
def eager_load(docs)
1726
docs.tap do |d|
1827
if eager_loadable?
@@ -23,11 +32,11 @@ def eager_load(docs)
2332

2433
# Load the associations for the given documents. This will be done
2534
# recursively to load the associations of the given documents'
26-
# subdocuments.
35+
# associated documents.
2736
#
2837
# @param [ Array<Mongoid::Association::Relatable> ] associations
2938
# The associations to load.
30-
# @param [ Array<Document> ] document The documents.
39+
# @param [ Array<Mongoid::Document> ] docs The documents.
3140
def preload(associations, docs)
3241
assoc_map = associations.group_by(&:inverse_class_name)
3342
docs_map = {}

lib/mongoid/association/embedded/embedded_in/proxy.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ module Mongoid
44
module Association
55
module Embedded
66
class EmbeddedIn
7-
# Proxy class for representing :embedded_in associations.
7+
# Transparent proxy for embedded_in associations.
8+
# An instance of this class is returned when calling the
9+
# association getter method on the child document. This
10+
# class inherits from Mongoid::Association::Proxy and forwards
11+
# most of its methods to the target of the association, i.e.
12+
# the parent document.
813
class Proxy < Association::One
914
# Instantiate a new embedded_in association.
1015
#

lib/mongoid/association/embedded/embeds_many/proxy.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ module Mongoid
66
module Association
77
module Embedded
88
class EmbedsMany
9-
# Proxy class for the :embeds_many association.
9+
# Transparent proxy for embeds_many associations.
10+
# An instance of this class is returned when calling the
11+
# association getter method on the parent document. This
12+
# class inherits from Mongoid::Association::Proxy and forwards
13+
# most of its methods to the target of the association, i.e.
14+
# the array of child documents.
1015
class Proxy < Association::Many
1116
include Batchable
1217

lib/mongoid/association/embedded/embeds_one/proxy.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ module Mongoid
44
module Association
55
module Embedded
66
class EmbedsOne
7-
# Proxy class for :embeds_one associations.
7+
# Transparent proxy for embeds_one associations.
8+
# An instance of this class is returned when calling the
9+
# association getter method on the parent document. This
10+
# class inherits from Mongoid::Association::Proxy and forwards
11+
# most of its methods to the target of the association, i.e.
12+
# the child document.
813
class Proxy < Association::One
914
# The valid options when defining this association.
1015
#

lib/mongoid/association/marshalable.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
module Mongoid
55
module Association
6+
7+
# Mixin module for Mongoid::Association::Proxy which adds
8+
# custom Marshal.dump functionality.
69
module Marshalable
710

811
# Provides the data needed to Marshal.dump an association proxy.

lib/mongoid/association/nested/many.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
module Mongoid
55
module Association
66
module Nested
7+
8+
# Builder class used to perform #accepts_nested_attributes_for
9+
# attribute assignment on many-to-n associations.
710
class Many
811
include Buildable
912

lib/mongoid/association/nested/nested_buildable.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
module Mongoid
55
module Association
66
module Nested
7+
8+
# Mixin module containing common functionality used to
9+
# perform #accepts_nested_attributes_for attribute assignment
10+
# on associations.
711
module Buildable
812

913
attr_accessor :attributes, :existing, :association, :options

0 commit comments

Comments
 (0)