Sha256: 2f53356890e7b3dfb0c575f29d509e9cf486fb27f455dd258c0795b73b281416

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 Bytes

Contents

# Locating 是地理定位,表示地理位置和被定位物体之间的关联。

class Unidom::Geo::Locating < ActiveRecord::Base

  self.table_name = 'unidom_locatings'

  include Unidom::Common::Concerns::ModelExtension

  belongs_to :location, class_name: 'Unidom::Geo::Location'
  belongs_to :located,  polymorphic: true
  belongs_to :locator,  polymorphic: true

  scope :location_is, ->(location) { where location: location }
  scope :located_is,  ->(located)  { where located:  located  }
  scope :located_by,  ->(locator)  { where locator:  locator  }

  def self.locate!(location, located, locator = nil, opened_at = Time.now)
    attributes = { opened_at: opened_at }
    if locator.present?
      attributes[:locator] = locator
    else
      attributes[:locator_id]   = Unidom::Common::NULL_UUID
      attributes[:locator_type] = ''
    end
    self.located_is(located).location_is(location).valid_at.alive.first_or_create! attributes
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-geo-0.3 app/models/unidom/geo/locating.rb