This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mongo_mapper' | |
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => Logger.new(STDOUT)) | |
# MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017) | |
MongoMapper.database = 'testing' | |
class Person | |
include MongoMapper::Document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Blog | |
include MongoMapper::Document | |
# Attributes :::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
key :title, String | |
key :category_id, ObjectId | |
key :archive_after, Time | |
# Assocations ::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
belongs_to :category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageLog | |
include MongoMapper::Document | |
# Attributes :::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
key :repeat_count, Integer, :default => 0 | |
key :patient_name, String, :default => 'Unknown', :index => true | |
key :patient_num, String, :default => 'Unknown', :index => true | |
key :patient_emr, String, :default => 'Unknown', :index => true | |
# Doctor info (number, name, group) | |
key :doctor, String, :default => 'Unknown', :index => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Idea | |
include MongoMapper::Document | |
key :brilliance, String, :default => "Dark Matter Sucks!" | |
many :ratings | |
belongs_to :user | |
key :user_id, ObjectId | |
def to_s | |
text = "#{user.name} had this IDEA: #{brilliance}\n\tRATINGS:\n" | |
ratings.each do |r| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Be sure to have mongod running | |
# Below is an attempt to show one way to have nested comments on a blog post | |
# I did not thoroughly examine whether it is bulletproof or performant. | |
# But it seems to work :-) | |
col = Blog.all() | |
col.each {|c| c.destroy } | |
col = Comment.all() | |
col.each {|c| c.destroy } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "Viewing the list of movies" do | |
it "shows the movies" do | |
movie1 = Movie.create(title: "Iron Man", | |
rating: "PG-13", | |
total_gross: 318412101.00, | |
description: "Tony Stark builds an armored suit to fight the throes of evil", | |
released_on: "2008-05-02", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# I spent 15 minutes creating a quick example for an email list... | |
describe "State" do | |
it 'has a list of states' do | |
State.respond_to?(:states) | |
expect(State.states).to have_key('AK') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dragonfly' | |
require 'dragonfly/mongo_data_store' | |
require 'mongo' | |
require 'uri' | |
# From https://devcenter.heroku.com/articles/mongohq#use-with-ruby | |
def get_connection | |
return @db_connection if @db_connection | |
db = URI.parse(ENV['MONGOHQ_URL']) |
NewerOlder