Custom mongoid field type
Attributes
| [R] | city | |
| [R] | country | |
| [R] | latitude | |
| [R] | longitude | |
| [R] | state | |
| [R] | zip |
Class Public methods
demongoize(attrs) Link
Get the object as it was stored in the database, and instantiate this custom class from it.
Source: show
# File app/models/analytics/location.rb, line 8 def self.demongoize(attrs) Location.new(attrs.presence || {}) end
evolve(object) Link
Converts the object that was supplied to a criteria and converts it into a database friendly form.
Source: show
# File app/models/analytics/location.rb, line 29 def self.evolve(object) case object when Location object.mongoize when nil {} else object.try(:to_h) || {} end end
mongoize(object) Link
Takes any possible object and converts it to how it would be stored in the database.
Source: show
# File app/models/analytics/location.rb, line 14 def self.mongoize(object) case object when Location object.mongoize when Hash Location.new(object).mongoize when nil Location.new({}).mongoize else object end end
new(attrs = {}) Link
Source: show
# File app/models/analytics/location.rb, line 40 def initialize(attrs = {}) attrs ||= {} @city = attrs.fetch(:city, "Unknown") @state = attrs.fetch(:state, "Unknown") @zip = attrs.fetch(:zip, "Unknown") @country = attrs.fetch(:country, "Unknown") @latitude = attrs.fetch(:coords, []).last || attrs.fetch(:latitude, 0.0) @longitude = attrs.fetch(:coords, []).first || attrs.fetch(:longitude, 0.0) end