Class: RussianPhone::Field
- Inherits:
-
Object
- Object
- RussianPhone::Field
- Defined in:
- lib/russian_phone/field.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#demongoize(object) ⇒ Object
Get the object as it was stored in the database, and instantiate this custom class from it.
-
#evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
-
#initialize(options = {}) ⇒ Field
constructor
A new instance of Field.
-
#is_a?(o) ⇒ Boolean
Mongoid 8 hack.
-
#mongoize(object) ⇒ Object
Takes any possible object and converts it to how it would be stored in the database.
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/russian_phone/field.rb', line 5 def @options end |
Instance Method Details
#demongoize(object) ⇒ Object
Get the object as it was stored in the database, and instantiate this custom class from it.
25 26 27 |
# File 'lib/russian_phone/field.rb', line 25 def demongoize(object) RussianPhone::Number.new(object, @options) end |
#evolve(object) ⇒ Object
Converts the object that was supplied to a criteria and converts it into a database friendly form.
41 42 43 44 45 46 |
# File 'lib/russian_phone/field.rb', line 41 def evolve(object) case object when RussianPhone::Number then object.mongoize else object end end |
#is_a?(o) ⇒ Boolean
Mongoid 8 hack
49 50 51 52 |
# File 'lib/russian_phone/field.rb', line 49 def is_a?(o) return true if o == Class super end |
#mongoize(object) ⇒ Object
Takes any possible object and converts it to how it would be stored in the database.
31 32 33 34 35 36 37 |
# File 'lib/russian_phone/field.rb', line 31 def mongoize(object) case object when RussianPhone::Number then object.mongoize when String then RussianPhone::Number.new(object, @options).mongoize else object end end |