File tree Expand file tree Collapse file tree 4 files changed +77
-11
lines changed Expand file tree Collapse file tree 4 files changed +77
-11
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,31 @@ please consult GitHub releases for detailed release notes and JIRA for
18
18
the complete list of issues fixed in each release, including bug fixes.
19
19
20
20
21
+ Configuration DSL No Longer Requires an Argument to its Block
22
+ -------------------------------------------------------------
23
+
24
+ It is now possible to use ``Mongoid.configure`` without
25
+ providing an argument to its block:
26
+
27
+ .. code-block:: ruby
28
+
29
+ Mongoid.configure do
30
+ connect_to("mongoid_test")
31
+
32
+ # Use config method when assigning variables
33
+ config.preload_models = true
34
+
35
+ Note that ``configure`` will continue to support a block argument.
36
+ The following is equivalent to the above:
37
+
38
+ .. code-block:: ruby
39
+
40
+ Mongoid.configure do |config|
41
+ config.connect_to("mongoid_test")
42
+
43
+ config.preload_models = true
44
+
45
+
21
46
Added ``Mongoid::Criteria`` finder methods
22
47
------------------------------------------
23
48
Original file line number Diff line number Diff line change @@ -58,9 +58,19 @@ module Mongoid
58
58
# }
59
59
# end
60
60
#
61
+ # @example Using a block without an argument. Use `config` inside
62
+ # the block to perform variable assignment.
63
+ #
64
+ # Mongoid.configure do
65
+ # connect_to("mongoid_test")
66
+ #
67
+ # config.preload_models = true
68
+ #
61
69
# @return [ Config ] The configuration object.
62
- def configure
63
- block_given? ? yield ( Config ) : Config
70
+ def configure ( &block )
71
+ return Config unless block_given?
72
+
73
+ block . arity == 0 ? Config . instance_exec ( &block ) : yield ( Config )
64
74
end
65
75
66
76
# Convenience method for getting the default client.
Original file line number Diff line number Diff line change @@ -127,6 +127,13 @@ module Config
127
127
# always return a Hash.
128
128
option :legacy_attributes , default : false
129
129
130
+ # Returns the Config singleton, for use in the configure DSL.
131
+ #
132
+ # @return [ self ] The Config singleton.
133
+ def config
134
+ self
135
+ end
136
+
130
137
# Has Mongoid been configured? This is checking that at least a valid
131
138
# client config exists.
132
139
#
Original file line number Diff line number Diff line change 13
13
end
14
14
end
15
15
16
- context "when a block is supplied" do
16
+ context "when a block is given" do
17
+ config_override :preload_models , false
17
18
18
- before do
19
- Mongoid . configure do |config |
20
- config . preload_models = true
19
+ context "with arity 0" do
20
+
21
+ before do
22
+ Mongoid . configure do
23
+ config . preload_models = true
24
+ end
25
+ end
26
+
27
+ it "sets the values on the config instance" do
28
+ expect ( Mongoid . preload_models ) . to be true
21
29
end
22
30
end
23
31
24
- after do
25
- Mongoid . configure do |config |
26
- config . preload_models = false
32
+ context "with arity 1" do
33
+
34
+ before do
35
+ Mongoid . configure do |config |
36
+ config . preload_models = true
37
+ end
38
+ end
39
+
40
+ it "sets the values on the config instance" do
41
+ expect ( Mongoid . preload_models ) . to be true
27
42
end
28
43
end
29
44
30
- it "sets the values on the config instance" do
31
- expect ( Mongoid . preload_models ) . to be true
45
+ context "with arity 2" do
46
+
47
+ before do
48
+ Mongoid . configure do |config , _other |
49
+ config . preload_models = true
50
+ end
51
+ end
52
+
53
+ it "sets the values on the config instance" do
54
+ expect ( Mongoid . preload_models ) . to be true
55
+ end
32
56
end
33
57
end
34
58
end
You can’t perform that action at this time.
0 commit comments