
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Documentation: http://alexeypetrushin.github.com/mongodb_model
Object Model for MongoDB (callbacks, validations, mass-assignment, finders, ...).
Other ODM usually try to cover simple but non-standard API of MongoDB behind complex ORM-like abstractions. This tool exposes simplicity and power of MongoDB and leverages its differences.
# Basic example of working with [Mongo Model][mongodb_model].
#
# In this example we'll create simple model and examine basic CRUD and
# querying operations.
require 'mongo/model'
# Connecting to test database and cleaning it before starting.
Mongo::Model.default_database_name = :default_test
Mongo::Model.default_database.clear
# Let's define Game Unit.
# Models are just plain Ruby Objects, there's no any Attribute Scheme,
# Types, Proxies, or other complex stuff, just use standard Ruby practices.
class Unit
# Inheriting our Unit Class from Mongo::Model (the `inherit` keyword is
# just a simple shortcut including Module and its ClassMethods).
inherit Mongo::Model
# You can specify collection name explicitly or omit it and it will be
# guessed from the class name.
collection :units
# There's no need to define attributes, just use plain old Ruby technics to
# of working with objects.
attr_accessor :name, :status, :stats
def inspect; name end
end
# Stats conaining statistics about Unit (it will be embedded into the
# Unit).
#
# There are no difference between main and embedded objects, all of them
# are just standard Ruby objects.
class Unit::Stats
inherit Mongo::Model
attr_accessor :attack, :life, :shield
end
# Let's create two great Heroes.
zeratul = Unit.new name: 'Zeratul', status: 'alive'
zeratul.stats = Unit::Stats.new attack: 85, life: 300, shield: 100
tassadar = Unit.new name: 'Tassadar', status: 'dead'
tassadar.stats = Unit::Stats.new attack: 0, life: 80, shield: 300
# Saving units to database
p zeratul.save # => true
p tassadar.save # => true
# We made error - mistakenly set Tassadar's attack as zero, let's fix it.
tassadar.stats.attack = 20
p tassadar.save # => true
# Querying, use standard MongoDB query.
p Unit.first(name: 'Zeratul') # => Zeratul
p Unit.all(name: 'Zeratul') # => [Zeratul]
Unit.all name: 'Zeratul' do |unit|
p unit # => Zeratul
end
# Simple dynamic finders (bang versions also availiable).
p Unit.by_name('Zeratul') # => Zeratul
p Unit.first_by_name('Zeratul') # => Zeratul
p Unit.all_by_name('Zeratul') # => [Zeratul]
# In this example we covered basics of [Mongo Model][mongodb_model],
# please go to [contents][mongodb_model] for more samples.
#
# [mongodb_model]: index.html
gem install mongodb_model
Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.
FAQs
Unknown package
We found that mongodb_model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.