Sha256: 8442138f640574075f07390871b33a4a548d8d5014311ec2768e0bd168c42c86

Contents?: true

Size: 1.3 KB

Versions: 14

Compression:

Stored size: 1.3 KB

Contents

class Address
  include Mongoid::Document

  field :_id, type: String, default: ->{ street.try(:parameterize) }

  attr_accessor :mode

  field :address_type
  field :number, type: Integer
  field :street
  field :city
  field :state
  field :post_code
  field :parent_title
  field :services, type: Array
  field :latlng, type: Array
  field :map, type: Hash

  embeds_many :locations, validate: false
  embeds_one :code, validate: false
  embeds_one :target, as: :targetable, validate: false

  embedded_in :addressable, polymorphic: true do
    def extension
      "Testing"
    end
    def doctor?
      title == "Dr"
    end
  end

  accepts_nested_attributes_for :locations, :code, :target

  belongs_to :account

  scope :without_postcode, where(postcode: nil)
  scope :rodeo, where(street: "Rodeo Dr") do
    def mansion?
      all? { |address| address.street == "Rodeo Dr" }
    end
  end

  validates_presence_of :street, on: :update
  validates_format_of :street, with: /\D/, allow_nil: true

  def set_parent=(set = false)
    self.parent_title = addressable.title if set
  end

  def <=>(other)
    street <=> other.street
  end

  class << self
    def california
      where(state: "CA")
    end

    def homes
      where(address_type: "Home")
    end

    def streets
      all.map(&:street)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongoid_geospatial-3.1.0 spec/models/address.rb
mongoid_geospatial-3.0.0 spec/models/address.rb
mongoid_geospatial-2.8.3 spec/models/address.rb
mongoid_geospatial-2.8.2 spec/models/address.rb
mongoid_geospatial-2.8.1 spec/models/address.rb
mongoid_geospatial-2.8.0 spec/models/address.rb
mongoid_geospatial-2.7.2 spec/models/address.rb
mongoid_geospatial-2.7.1 spec/models/address.rb
mongoid_geospatial-2.7.0 spec/models/address.rb
mongoid_geospatial-2.5.1 spec/models/address.rb
mongoid_geospatial-2.5.0 spec/models/address.rb
mongoid_geospatial-2.3.0 spec/models/address.rb
mongoid_geospatial-2.2.0 spec/models/address.rb
mongoid_geospatial-2.0.0 spec/models/address.rb