Sha256: bf8af300e38bb7e9b534eeffacf29a81c3cb969ee1bf05420bc79e858d6ccf96

Contents?: true

Size: 982 Bytes

Versions: 3

Compression:

Stored size: 982 Bytes

Contents

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

class Unidom::Geo::Locating < Unidom::Geo::ApplicationRecord

  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: nil, located: nil, 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

3 entries across 3 versions & 1 rubygems

Version Path
unidom-geo-1.4.3 app/models/unidom/geo/locating.rb
unidom-geo-1.4.2 app/models/unidom/geo/locating.rb
unidom-geo-1.4.1 app/models/unidom/geo/locating.rb