realogy 0.6.9 → 0.6.10

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
  SHA256:
3
- metadata.gz: e4cd27d1efeb5f696a0c1e78300083b7ead01f7f380bd1ebf8c1d420b25dd870
4
- data.tar.gz: 5c275d47d826831f3fda7ec142e907069b7de334f2afd1d31bb84380caf5b40e
3
+ metadata.gz: 35e5c36fc0a5bd0540a03d4a2b15a27f0308843e3ee9f8c444d7b62ab9ab449f
4
+ data.tar.gz: 6d7765533f529ceff5d733cb2d524ca2dd82ff02620f8216ff6c253b09d6f2c6
5
5
  SHA512:
6
- metadata.gz: c4f05a3939ca6c449d9b357cfb1581d8ba6f2dc031104b203c25f6bd056a5099c271dcfb26a0db087778dead92d7e5446efb954cdc03e850ff8d6d8aced19f6f
7
- data.tar.gz: a81cdbf6e7709007e584300014b1c09e65f617ac028ba9394493779aabf78463cac56542bd6988a51e4bd725efc2d4238cd5af28d700a2644ccc14a29eb03961
6
+ metadata.gz: 0ca7f3041d3b123890046ca83bd0558b8a713030253186a9fc2882a5fc4297f09d4b89b04a119062a0c9ba8d7c32fdcbe01d2942bd696b1b87bd499fc45b0e0d
7
+ data.tar.gz: 9866700d33eda367d057882ab5b127eb8bc106f369315db4a7d16f75863baab767f91dcbeb27dd0db0e91a6fd30c3567da7a14845f1e00e17fc28fa0035f6d89
@@ -6,58 +6,79 @@ class Realogy::Entity < ApplicationRecord
6
6
  validates :last_update_on, presence: true
7
7
 
8
8
  def needs_updating?
9
- self.new_record? || self.last_update_on_changed? || self.data.blank?
9
+ new_record? || last_update_on_changed? || data.blank?
10
10
  end
11
11
 
12
- def self.triage hash
13
- @object = self.find_or_initialize_by(entity_id: [hash["entityId"], hash["id"]].compact.first)
12
+ def self.triage(hash)
13
+ entity_id = [hash["entityId"], hash["id"]].compact.first
14
+ @object = find_or_initialize_by(entity_id: entity_id)
14
15
  @object.last_update_on = hash["lastUpdateOn"].to_s.to_datetime
15
- @object.populate if @object.needs_updating?
16
+
17
+ if data_provided_in_hash?(hash)
18
+ @object.data = extract_entity_data(hash)
19
+ @object.save if @object.changed?
20
+ elsif @object.needs_updating?
21
+ @object.populate
22
+ end
16
23
  end
17
24
 
18
25
  def get_data
19
26
  call = ["get_", self.class.to_s.downcase.split("::").last, "_by_id"].join.to_sym
20
- Realogy::DataSync.client.__send__(call, self.entity_id)
27
+ Realogy::DataSync.client.__send__(call, entity_id)
21
28
  end
22
29
 
23
30
  def populate
24
31
  result = get_data
25
32
  self.data = result unless result.blank?
26
- self.save if self.changed?
33
+ save if changed?
27
34
  end
28
35
 
29
36
  def dig_for_array(*path)
30
- return nil unless (json = self.data).is_a?(Hash)
37
+ return nil unless (json = data).is_a?(Hash)
31
38
  (v = json.dig(*path)).is_a?(Array) ? v : nil
32
39
  end
33
40
 
34
41
  def dig_for_boolean(*path)
35
- return nil unless (json = self.data).is_a?(Hash)
42
+ return nil unless (json = data).is_a?(Hash)
36
43
  (v = json.dig(*path)).to_s.upcase.eql?("TRUE") ? true : nil
37
44
  end
38
45
 
39
46
  def dig_for_datetime(*path)
40
- self.data.dig(*path).to_datetime rescue nil
47
+ data.dig(*path).to_datetime rescue nil
41
48
  end
42
49
 
43
50
  def dig_for_decimal(*path)
44
- return nil unless (json = self.data).is_a?(Hash)
51
+ return nil unless (json = data).is_a?(Hash)
45
52
  (v = json.dig(*path).to_f) != 0.0 ? v : nil
46
53
  end
47
54
 
48
55
  def dig_for_hash(*path)
49
- return nil unless (json = self.data).is_a?(Hash)
56
+ return nil unless (json = data).is_a?(Hash)
50
57
  (v = json.dig(*path)).is_a?(Hash) ? v : nil
51
58
  end
52
59
 
53
60
  def dig_for_integer(*path)
54
- return nil unless (json = self.data).is_a?(Hash)
61
+ return nil unless (json = data).is_a?(Hash)
55
62
  (v = json.dig(*path).to_i) != 0 ? v : nil
56
63
  end
57
64
 
58
65
  def dig_for_string(*path)
59
- return nil unless (json = self.data).is_a?(Hash)
66
+ return nil unless (json = data).is_a?(Hash)
60
67
  (v = json.dig(*path)).to_s.present? ? (v.eql?("0") ? nil : v) : nil
61
68
  end
62
69
 
70
+ class << self
71
+ private
72
+
73
+ def data_provided_in_hash?(hash)
74
+ # Check if hash contains entity data beyond just metadata fields
75
+ metadata_keys = %w[entityId id lastUpdateOn class action]
76
+ (hash.keys - metadata_keys).any?
77
+ end
78
+
79
+ def extract_entity_data(hash)
80
+ # Remove metadata fields and return just the entity data
81
+ hash.except("class", "action")
82
+ end
83
+ end
63
84
  end
@@ -1,3 +1,3 @@
1
1
  module Realogy
2
- VERSION = "0.6.9"
2
+ VERSION = "0.6.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Edlund