Module: Mongoize::ClassMethods
- Defined in:
- lib/money/mongoid/3x/money.rb
Instance Method Summary collapse
- #custom_between(field, value, options = {}) ⇒ Object
- #custom_between?(field, value) ⇒ Boolean
- #custom_serialization?(operator) ⇒ Boolean
- #custom_specify(name, operator, value, options = {}) ⇒ Object
- #demongoize(value) ⇒ Object
- #evolve(object) ⇒ Object
Instance Method Details
#custom_between(field, value, options = {}) ⇒ Object
40 41 42 |
# File 'lib/money/mongoid/3x/money.rb', line 40 def custom_between(field, value, = {}) { "$gte" => ::Money.new(value.min, value.iso_code), "$lte" => ::Money.new(value.max, value.iso_code) } end |
#custom_between?(field, value) ⇒ Boolean
44 45 46 |
# File 'lib/money/mongoid/3x/money.rb', line 44 def custom_between? field, value true end |
#custom_serialization?(operator) ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/money/mongoid/3x/money.rb', line 20 def custom_serialization?(operator) return false unless operator case operator when "$gte", "$gt", "$lt", "$lte" true else false end end |
#custom_specify(name, operator, value, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/money/mongoid/3x/money.rb', line 30 def custom_specify(name, operator, value, = {}) money = value.__evolve_to_money__ case operator when "$gte", "$gt", "$lt", "$lte" specify_with_multiple_currencies(name, operator, money, ) else raise RuntimeError, "Unsupported operator" end end |
#demongoize(value) ⇒ Object
12 13 14 |
# File 'lib/money/mongoid/3x/money.rb', line 12 def demongoize(value) value && ::Money.new( get_cents(value), get_currency(value) ) end |
#evolve(object) ⇒ Object
16 17 18 |
# File 'lib/money/mongoid/3x/money.rb', line 16 def evolve(object) object && object.__evolve_to_money__.mongoize end |