mongo_mapper-strict_keys 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +6 -3
- data/lib/mongo_mapper/strict_keys.rb +5 -0
- data/lib/mongo_mapper/strict_keys/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
|
5
5
|
### In your Gemfile:
|
6
6
|
|
7
|
-
gem 'mongo_mapper-strict_keys', '~>0.0.
|
7
|
+
gem 'mongo_mapper-strict_keys', '~>0.0.5'
|
8
8
|
|
9
9
|
To force strict keys for all models, from the outset:
|
10
10
|
|
11
|
-
gem 'mongo_mapper-strict_keys', '~>0.0.
|
11
|
+
gem 'mongo_mapper-strict_keys', '~>0.0.5', :require => 'mongo_mapper/strict_keys/force_plugin'
|
12
12
|
|
13
13
|
### In your Source Code / Model:
|
14
14
|
|
@@ -16,5 +16,8 @@ To force strict keys for all models, from the outset:
|
|
16
16
|
|
17
17
|
class StrictModel
|
18
18
|
include MongoMapper::Document
|
19
|
-
|
19
|
+
|
20
|
+
strict_keys!
|
20
21
|
end
|
22
|
+
|
23
|
+
If you already required the force\_plugin, then you don't need to specify 'strict_keys!'
|
@@ -11,10 +11,15 @@ module MongoMapper
|
|
11
11
|
module ClassMethods; end
|
12
12
|
|
13
13
|
module InstanceMethods
|
14
|
+
# @param [Symbol, String] name The name of the key to be ensured
|
15
|
+
# @return [true] This method either returns true or raises an exception
|
16
|
+
# @raise [ArgumentError] If 'name' has not been specified as a key
|
17
|
+
# @see MongoMapper::Plugins::Keys#key
|
14
18
|
def ensure_key_exists(name)
|
15
19
|
unless respond_to?("#{name}=")
|
16
20
|
raise ArgumentError.new("Attribute '#{name}' has not been explicitly defined as a key.")
|
17
21
|
end
|
22
|
+
true
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|