Module: MongoMapper::Plugins::StrictKeys::InstanceMethods

Defined in:
lib/mongo_mapper/strict_keys.rb

Instance Method Summary collapse

Instance Method Details

#ensure_key_exists(name) ⇒ true

Returns This method either returns true or raises an exception.

Parameters:

  • name (Symbol, String)

    The name of the key to be ensured

Returns:

  • (true)

    This method either returns true or raises an exception

Raises:

  • (ArgumentError)

    If ‘name’ has not been specified as a key

See Also:

  • Keys#key


18
19
20
21
22
23
# File 'lib/mongo_mapper/strict_keys.rb', line 18

def ensure_key_exists(name)
  unless respond_to?("#{name}=")
    raise ArgumentError.new("Attribute '#{name}' has not been explicitly defined as a key.")
  end
  true
end