mas-rad_core 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb9db5a0fd81f696ed5a1c6dcbba990bf24fe66a
4
- data.tar.gz: 9009e02c96124243e412f337f430b95ae7dd9633
3
+ metadata.gz: 40e538321611ab43bde99c5560d783c4e6cc94c0
4
+ data.tar.gz: 13f3492b04b69563e8a295a43fda7bb8b89b91ba
5
5
  SHA512:
6
- metadata.gz: 4ca3c8152dcf16dde34f242369c84f6caf4889a6c02d7e7c7b060d5a4072a7b4744e17bb05f5650a8ef790cc57c46a89190fc45d71ae50e788ffed5e4dafa43f
7
- data.tar.gz: 7bd5a3a224682504174a4205364b10ffb64309c0e76b5fedf71480fceadcc46bbbafea32a0a6c4a29e8085cdc5411800a1b65b8a803dbd23bf3b19d2f9ab014f
6
+ metadata.gz: 6fe763a16a30a53637db0b054185aa2f454b8ac71fe9e0cd325935a73cf2424fcf9280f6bc682f045375b2082121bc0ad3b0bea96f3e3f466aab96c7f583b128
7
+ data.tar.gz: 6cbed78f68d63f29bf9caccc59befd8bf5a7e94ba47830233549bb02ef3b0dd366b5f7ba710580f4e4786c6fdcda3e8d54f376e4e3abbb71fd1a9770f855fa21
@@ -1,8 +1,15 @@
1
1
  class GeocodeAdviserJob < ActiveJob::Base
2
2
  def perform(adviser)
3
- coordinates = Geocoder.coordinates(adviser.full_street_address)
4
- coordinates ? stat(:success) : stat(:failed)
5
- adviser.geocode!(coordinates)
3
+ Geocoder.coordinates(adviser.full_street_address).tap do |coords|
4
+ adviser.geocode!(coords)
5
+
6
+ if coords
7
+ IndexFirmJob.perform_later(adviser.firm)
8
+ stat :success
9
+ else
10
+ stat :failed
11
+ end
12
+ end
6
13
  end
7
14
 
8
15
  private
@@ -12,8 +12,6 @@ class Adviser < ActiveRecord::Base
12
12
 
13
13
  before_validation :upcase_postcode
14
14
 
15
- after_save :schedule_indexing, if: -> { valid? && geocoded? }
16
-
17
15
  validates_acceptance_of :confirmed_disclaimer, accept: true
18
16
 
19
17
  validates :travel_distance,
@@ -40,7 +38,11 @@ class Adviser < ActiveRecord::Base
40
38
  end
41
39
 
42
40
  def geocoded?
43
- latitude.present? && longitude.present?
41
+ coordinates.compact.present?
42
+ end
43
+
44
+ def coordinates
45
+ [latitude, longitude]
44
46
  end
45
47
 
46
48
  def field_order
@@ -60,10 +62,6 @@ class Adviser < ActiveRecord::Base
60
62
  end
61
63
  end
62
64
 
63
- def schedule_indexing
64
- IndexFirmJob.perform_later(firm)
65
- end
66
-
67
65
  def upcase_postcode
68
66
  postcode.upcase! if postcode.present?
69
67
  end
@@ -1,4 +1,8 @@
1
1
  module Geocodable
2
+ def self.included(model)
3
+ model.scope :geocoded, -> { model.where.not(latitude: nil, longitude: nil) }
4
+ end
5
+
2
6
  def latitude=(value)
3
7
  value = value.to_f.round(6) unless value.nil?
4
8
  write_attribute(:latitude, value)
@@ -12,6 +12,10 @@ class FirmSerializer < ActiveModel::Serializer
12
12
 
13
13
  has_many :advisers
14
14
 
15
+ def advisers
16
+ object.advisers.geocoded
17
+ end
18
+
15
19
  def postcode_searchable
16
20
  object.postcode_searchable?
17
21
  end
@@ -1,5 +1,5 @@
1
1
  module MAS
2
2
  module RadCore
3
- VERSION = '0.0.12'
3
+ VERSION = '0.0.13'
4
4
  end
5
5
  end