unidom-geo 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c45e31e1ee141061b5ce9d4a8555cad2e972352
4
- data.tar.gz: 10a83320f101878f1c165e5658567967a1eca23d
3
+ metadata.gz: 4d804f7b473b75141cb773b78046619750b7d4c6
4
+ data.tar.gz: ea65c588897d92dea09f9832a6d3bad8abbd653c
5
5
  SHA512:
6
- metadata.gz: 1c4d28720aa4e64f3b6c79a18f8a440fe853dc07d01088fe1d719257e3d3e9b9bfa2628e2f4041dee132d7dc0ecec3d3acc3a62be43805a1eb589f10892161b3
7
- data.tar.gz: 79cda3a5bc8a42c34251dd6fc4599998eee8c7a9bf0bd397e09de2a6b5bc668557e128d94f91ee2cd62adb4b1c3576a9849707fa49cc9f8c2bd249681c0c1a19
6
+ metadata.gz: df39c01b430a9c26d7e5da6d7d9a3d8e8ceb856088b889a3ed1e1a978d7ea320bbf7d76ef34214f5055156b33c84e25246200dc143cab98d7a191be32bf8b895
7
+ data.tar.gz: 7844ceb083e5ce0194983aa0d3746a573732e91f0d750fa283985f192b1c2dd46f9cc6f2dd309a97b6ed4e8cff50741b549a942e06d56b7dcf5d93f893ce2e46
data/README.md CHANGED
@@ -31,6 +31,9 @@ active_locatings = location.locatings.valid_at.alive
31
31
  location.locate! shop, by: person
32
32
  # or
33
33
  Unidom::Geo::Locating.locate! location: location, located: shop
34
+
35
+ # Determine whether a shop was located to a given location at a given time.
36
+ location.locate? shop, at: Time.now
34
37
  ```
35
38
 
36
39
  ## Include the Concerns:
@@ -43,6 +46,7 @@ include Unidom::Geo::Concerns::AsRegion
43
46
  The As Located concern do the following tasks for the includer automatically:
44
47
  1. Define the has_many :locatings macro as: ``has_many :locatings, class_name: 'Unidom::Geo::Locating', as: :located``
45
48
  2. Define the has_many :locations macro as: ``has_many :locations, through: :locatings, source: :location``
49
+ 3. Define the #is_located! method as: ``is_located!(to: nil, by: nil, at: Time.now)``
46
50
 
47
51
  ### As Region concern
48
52
  The As Region concern do the following tasks for the includer automatically:
@@ -7,6 +7,10 @@ module Unidom::Geo::Concerns::AsLocated
7
7
  has_many :locatings, class_name: 'Unidom::Geo::Locating', as: :located
8
8
  has_many :locations, through: :locatings, source: :location
9
9
 
10
+ def is_located!(to: nil, by: nil, at: Time.now)
11
+ locatings.location_is(to).valid_at(now: at).alive.first_or_create! locator: by, opened_at: at
12
+ end
13
+
10
14
  end
11
15
 
12
16
  module ClassMethods
@@ -25,7 +25,11 @@ class Unidom::Geo::Location < ActiveRecord::Base
25
25
  scope :postal_address_is, ->(postal_address) { where postal_address: postal_address }
26
26
 
27
27
  def locate!(located, by: nil, at: Time.now)
28
- locatings.create! located: located, locator: by, opened_at: at
28
+ locatings.located_is(located).valid_at(now: at).alive.first_or_create! locator: by, opened_at: at
29
+ end
30
+
31
+ def locate?(located, at: Time.now)
32
+ locatings.located_is(located).valid_at(now: at).alive.exists?
29
33
  end
30
34
 
31
35
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Geo
3
- VERSION = '1.1'.freeze
3
+ VERSION = '1.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-geo
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common