Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add mongoid 4 support

  • Loading branch information...
commit b3b79f3b97b86259acecff80598daea3c44faed2 1 parent 71a9cdc
@felipero felipero authored
Showing with 2 additions and 51 deletions.
  1. +2 −4 lib/money-rails/hooks.rb
  2. +0 −47 lib/money-rails/mongoid/three.rb
View
6 lib/money-rails/hooks.rb
@@ -18,10 +18,8 @@ def self.init
if defined? ::Mongoid
if ::Mongoid::VERSION =~ /^2(.*)/
require 'money-rails/mongoid/two' # Loading the file is enough
- end
-
- if ::Mongoid::VERSION =~ /^3(.*)/
- require 'money-rails/mongoid/three'
+ else
+ require 'money-rails/mongoid/money'
end
end
View
47 lib/money-rails/mongoid/three.rb
@@ -1,47 +0,0 @@
-class Money
-
- # Converts an object of this instance into a database friendly value.
- def mongoize
- {
- :cents => cents,
- :currency_iso => currency.iso_code
- }
- end
-
- class << self
-
- # Get the object as it was stored in the database, and instantiate
- # this custom class from it.
- def demongoize(object)
- if object.is_a?(Hash)
- object = object.symbolize_keys
- object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil
- else
- nil
- end
- end
-
- # Takes any possible object and converts it to how it would be
- # stored in the database.
- def mongoize(object)
- case
- when object.is_a?(Money) then object.mongoize
- when object.is_a?(Hash) then
- object.symbolize_keys! if object.respond_to?(:symbolize_keys!)
- ::Money.new(object[:cents], object[:currency_iso]).mongoize
- when object.respond_to?(:to_money) then
- object.to_money.mongoize
- else object
- end
- end
-
- # Converts the object that was supplied to a criteria and converts it
- # into a database friendly form.
- def evolve(object)
- case object
- when Money then object.mongoize
- else object
- end
- end
- end
-end

0 comments on commit b3b79f3

Please sign in to comment.
Something went wrong with that request. Please try again.