-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor if statements to be inside individual patch files for clarity.
- Loading branch information
1 parent
ea6a43c
commit 39f7eeb
Showing
21 changed files
with
1,576 additions
and
1,178 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
require 'version' | ||
|
||
if Mongoid::VERSION =~ /\A3\./ | ||
require 'patches/atomic' | ||
require 'patches/reorder' | ||
end | ||
|
||
if Mongoid::VERSION =~ /\A[345]\./ | ||
require 'patches/big_decimal' | ||
end | ||
|
||
if defined?(Moped) | ||
require 'patches/instrument' if Moped::VERSION =~ /\A1\./ | ||
require 'patches/db_commands' | ||
end | ||
require 'patches/atomic' | ||
require 'patches/big_decimal' | ||
require 'patches/db_commands' | ||
require 'patches/instrument' | ||
require 'patches/reorder' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
# Fixes inconsistent behavior of BigDecimal. This can be removed after | ||
# https://github.com/mongodb/mongoid/pull/4164 is merged, planned for Mongoid 6. | ||
|
||
module MongoidMonkey | ||
module Mongoid | ||
module Extensions | ||
module BigDecimal | ||
if Mongoid::VERSION =~ /\A[345]\./ | ||
|
||
def numeric? | ||
true | ||
end | ||
|
||
module ClassMethods | ||
module MongoidMonkey | ||
module Mongoid | ||
module Extensions | ||
module BigDecimal | ||
|
||
def demongoize(object) | ||
object && object.numeric? ? ::BigDecimal.new(object.to_s) : nil | ||
def numeric? | ||
true | ||
end | ||
|
||
def mongoize(object) | ||
object && object.numeric? ? object.to_s : nil | ||
module ClassMethods | ||
|
||
def demongoize(object) | ||
object && object.numeric? ? ::BigDecimal.new(object.to_s) : nil | ||
end | ||
|
||
def mongoize(object) | ||
object && object.numeric? ? object.to_s : nil | ||
end | ||
end | ||
end | ||
end | ||
|
||
module String | ||
module String | ||
|
||
def numeric? | ||
true if Float(self) rescue (self =~ /^NaN|\-?Infinity$/) | ||
def numeric? | ||
true if Float(self) rescue (self =~ /^NaN|\-?Infinity$/) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
::BigDecimal.__send__(:include, MongoidMonkey::Mongoid::Extensions::BigDecimal) | ||
::BigDecimal.extend(MongoidMonkey::Mongoid::Extensions::BigDecimal::ClassMethods) | ||
::BigDecimal.__send__(:include, MongoidMonkey::Mongoid::Extensions::BigDecimal) | ||
::BigDecimal.extend(MongoidMonkey::Mongoid::Extensions::BigDecimal::ClassMethods) | ||
|
||
::String.__send__(:include, MongoidMonkey::Mongoid::Extensions::String) | ||
::String.__send__(:include, MongoidMonkey::Mongoid::Extensions::String) | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
# Instrument Moped 1.x same as Moped 2.x. | ||
# Useful for integration with third-party services. | ||
|
||
module Moped | ||
module Instrumentable | ||
class Noop | ||
if defined?(Moped) && Moped::VERSION =~ /\A1\./ | ||
|
||
class << self | ||
module Moped | ||
module Instrumentable | ||
class Noop | ||
|
||
# Do not instrument anything. | ||
def instrument(name, payload = {}) | ||
yield payload if block_given? | ||
class << self | ||
|
||
# Do not instrument anything. | ||
def instrument(name, payload = {}) | ||
yield payload if block_given? | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module Moped | ||
module Instrumentable | ||
module Moped | ||
module Instrumentable | ||
|
||
TOPIC = "query.moped" | ||
TOPIC = "query.moped" | ||
|
||
def instrumenter | ||
@instrumenter ||= Moped::Instrumentable::Noop | ||
end | ||
def instrumenter | ||
@instrumenter ||= Moped::Instrumentable::Noop | ||
end | ||
|
||
def instrument(name, payload = {}, &block) | ||
instrumenter.instrument(name, payload, &block) | ||
def instrument(name, payload = {}, &block) | ||
instrumenter.instrument(name, payload, &block) | ||
end | ||
end | ||
end | ||
end | ||
|
||
module Moped | ||
class Node | ||
include Moped::Instrumentable | ||
module Moped | ||
class Node | ||
include Moped::Instrumentable | ||
|
||
def logging_with_instrument(operations, &block) | ||
instrument(TOPIC, prefix: " MOPED: #{resolved_address}", ops: operations) do | ||
logging_without_instrument(operations, &block) | ||
def logging_with_instrument(operations, &block) | ||
instrument(TOPIC, prefix: " MOPED: #{resolved_address}", ops: operations) do | ||
logging_without_instrument(operations, &block) | ||
end | ||
end | ||
alias_method_chain :logging, :instrument | ||
end | ||
alias_method_chain :logging, :instrument | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# Backport of Criteria#reorder method from Mongoid 4 to Mongoid 3. | ||
|
||
module Origin | ||
module Optional | ||
if Mongoid::VERSION =~ /\A3\./ | ||
|
||
def reorder(*spec) | ||
options.delete(:sort) | ||
order_by(*spec) | ||
module Origin | ||
module Optional | ||
|
||
def reorder(*spec) | ||
options.delete(:sort) | ||
order_by(*spec) | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module MongoidMonkey | ||
VERSION = '0.1.2' | ||
VERSION = '0.1.3' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
class Account | ||
include Mongoid::Document | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
class Address | ||
include Mongoid::Document | ||
field :street | ||
field :name, localize: true | ||
embedded_in :addressable, polymorphic: true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
class Draft | ||
include Mongoid::Document | ||
field :text | ||
recursively_embeds_one | ||
index text: 1 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
class Person | ||
include Mongoid::Document | ||
|
||
index age: 1 | ||
index addresses: 1 | ||
index dob: 1 | ||
index name: 1 | ||
index title: 1 | ||
index({ ssn: 1 }, { unique: true }) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
class User | ||
include Mongoid::Document | ||
field :name | ||
index name: 1 | ||
end |
Oops, something went wrong.