Sha256: 67894b1e0379380d7e6002b16b821b97c5bab80f1dfe5e172262435dfe2f89db

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

##
# As Located 是为地标提供的领域逻辑关注点。

module Unidom::Geo::Concerns::AsLocated

  extend  ActiveSupport::Concern
  include Unidom::Common::Concerns::ArgumentValidation

  included do |includer|

    has_many :locatings, class_name: 'Unidom::Geo::Locating', as:     :located
    has_many :locations, through:    :locatings,              source: :location

    ##
    # 将当前位置与地标 to 关联起来。如:
    # location = Unidom::Geo::Location.first
    # shop.is_located! to: location, by: current_person
    def is_located!(to: nil, by: nil, at: Time.now)

      assert_present! :to, to
      assert_present! :by, by
      assert_present! :at, at

      locatings.location_is(to).valid_at(now: at).alive.first_or_create! locator: by, opened_at: at

    end

    ##
    # 检查当前位置与地标 to 在指定的时间 at (缺省是当前时间)是否关联起来了。
    # location = Unidom::Geo::Location.first
    # 如: shop.is_located? to: location, at: Time.now
    def is_located?(to: nil, at: Time.now)

      assert_present! :to, to
      assert_present! :at, at

      locatings.location_is(to).valid_at(now: at).alive.exists?

    end

  end

  module ClassMethods
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
unidom-geo-2.0.1 app/models/unidom/geo/concerns/as_located.rb
unidom-geo-2.0 app/models/unidom/geo/concerns/as_located.rb
unidom-geo-1.5.9 app/models/unidom/geo/concerns/as_located.rb
unidom-geo-1.5.8 app/models/unidom/geo/concerns/as_located.rb
unidom-geo-1.5.7 app/models/unidom/geo/concerns/as_located.rb