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
use test | |
db.entities.drop() | |
db.entities.insert({_id: 1}) | |
db.entities.update({ "_id": 1 }, {"$set": {"foo": "foo"} }) | |
db.entities.update({ "_id": 1 }, {"$set": {"a": "a"} }) | |
db.entities.update({ "_id": 1 }, {"$set": {"c": "c"} }) | |
db.entities.update({ "_id": 1 }, {"$set": {"b": "b"} }) | |
db.entities.find() |
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 'benchmark' | |
class Coffee | |
def cost | |
2 | |
end | |
def origin | |
"Colombia" | |
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
# encoding: utf-8 | |
require "spec_helper" | |
class Person | |
include Mongoid::Document | |
has_many :pets | |
field :name | |
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 'oj' | |
require 'active_support/all' | |
require 'benchmark' | |
null = nil | |
hash = { | |
"photo"=> { | |
"id"=> 4928401, | |
"user_id"=> 164677, |
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" | |
class Publication | |
include Mongoid::Document | |
embeds_many :issues | |
end | |
class Issue | |
include Mongoid::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
require "spec_helper" | |
class User | |
include Mongoid::Document | |
has_and_belongs_to_many :cars, inverse_of: :users | |
has_one :favorite_car, class_name: 'Car', inverse_of: :person | |
before_validation :set_default_favorite_car, on: :create |
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
module IdentityCache | |
BACKEND_KEY = 'idc:backend:key' | |
def with_memoization(&block) | |
Thread.current[IdentityCache::BACKEND_KEY] = MemoizedDecorator.new(IdentityCache.cache_backend) | |
yield | |
ensure | |
Thread.current[IdentityCache::BACKEND_KEY] = nil | |
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
diff --git a/lib/identity_cache/memcached_adapter.rb b/lib/identity_cache/memcached_adapter.rb | |
index 9aa9e56..c817dd8 100644 | |
--- a/lib/identity_cache/memcached_adapter.rb | |
+++ b/lib/identity_cache/memcached_adapter.rb | |
@@ -17,14 +17,11 @@ module IdentityCache | |
super(servers, opts.merge(support_cas: true)) | |
end | |
- %w{delete incr decr append prepend}.each do |meth| | |
- define_method(meth) do |*args| |
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 Ship | |
include Mongoid::Document | |
has_one :vehicle | |
end | |
class Vehicle | |
include Mongoid::Document | |
belongs_to :ship | |
end | |
irb(main):009:0> s = Ship.new |
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 Cursor | |
include Enumerable | |
def each | |
p "cursor #{Thread.current.object_id}" | |
yield(1) | |
yield(2) | |
end | |
end |