g5_updatable 0.6.1 → 0.7.0
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 +4 -4
- data/README.md +10 -0
- data/lib/g5_updatable/locations_updater.rb +14 -1
- data/lib/g5_updatable/version.rb +1 -1
- data/spec/dummy/config/database.yml +2 -4
- data/spec/dummy/db/schema.rb +4 -4
- data/spec/dummy/log/test.log +2106 -14658
- data/spec/lib/g5_updatable/locations_updater_spec.rb +39 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb73a50f2ccd171abc638c249de6ac44691d3767
|
4
|
+
data.tar.gz: 6c31e1de5ebae2044c3aff58d6fddcf7d7936c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d4402c11532af307a63413cff19169a055c5792ea545bc1700e1e7d3aafc5a7f546419130be318c1266d759a9b973929386a94c6219e3259c0be3b30d349a1f
|
7
|
+
data.tar.gz: 74ae9fac9dc83ba36e84a20b0f20cdc0926a912bbfe905c06a4af9643ad16a96f2cfb98a22ed84463a66fddbb8dd48042ab57bcd12951950e75e70cd4ff727ad
|
data/README.md
CHANGED
@@ -56,6 +56,16 @@ G5 Updatable also exposes two GET endpoints which return JSON:
|
|
56
56
|
* '/g5_updatable/locations/:urn' returns information about a location
|
57
57
|
* '/g5_updatable/syncs' returns updated_at timetamp of the most recent location sync
|
58
58
|
|
59
|
+
### Hooks
|
60
|
+
|
61
|
+
To execute code every time a location is updated:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
G5Updatable::LocationsUpdader.on_update do |g5_updatable_location|
|
65
|
+
puts "G5Updatable::Location##{g5_updatable_location.id} was just updated"
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
59
69
|
### Associations
|
60
70
|
|
61
71
|
You will likely have models in your own application that are associated with a Client or Location. A module is available to include in your related models to support this association. Assuming your model has a `client_uid` or `location_uid` string field respectively, you can do the following:
|
@@ -1,13 +1,25 @@
|
|
1
1
|
class G5Updatable::LocationsUpdater
|
2
|
+
|
3
|
+
cattr_writer :on_update_callbacks
|
4
|
+
|
2
5
|
def initialize(foundation_client)
|
3
6
|
@client_uid = foundation_client.uid
|
4
7
|
@g5_locations = foundation_client.locations
|
5
8
|
end
|
6
9
|
|
10
|
+
def self.on_update(&block)
|
11
|
+
self.on_update_callbacks ||= []
|
12
|
+
self.on_update_callbacks += [block]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.on_update_callbacks
|
16
|
+
@@on_update_callbacks || []
|
17
|
+
end
|
18
|
+
|
7
19
|
def update
|
8
20
|
@g5_locations.each do |g5_location|
|
9
21
|
attributes = g5_location.location_hash.dup
|
10
|
-
G5Updatable::Location.
|
22
|
+
location = G5Updatable::Location.
|
11
23
|
find_or_initialize_by(uid: attributes[:uid]).
|
12
24
|
update_attributes!(
|
13
25
|
urn: attributes[:urn],
|
@@ -16,6 +28,7 @@ class G5Updatable::LocationsUpdater
|
|
16
28
|
properties: attributes,
|
17
29
|
updated_at: DateTime.now
|
18
30
|
)
|
31
|
+
self.class.on_update_callbacks.each { |cb| cb.call(location) }
|
19
32
|
end
|
20
33
|
destroy_orphaned_locations!
|
21
34
|
end
|
data/lib/g5_updatable/version.rb
CHANGED
data/spec/dummy/db/schema.rb
CHANGED
@@ -16,14 +16,14 @@ ActiveRecord::Schema.define(version: 20141222072623) do
|
|
16
16
|
# These are extensions that must be enabled in order to support this database
|
17
17
|
enable_extension "plpgsql"
|
18
18
|
|
19
|
-
create_table "favorite_foods", force:
|
19
|
+
create_table "favorite_foods", force: :cascade do |t|
|
20
20
|
t.string "name"
|
21
21
|
t.string "location_uid"
|
22
22
|
t.datetime "created_at"
|
23
23
|
t.datetime "updated_at"
|
24
24
|
end
|
25
25
|
|
26
|
-
create_table "g5_updatable_clients", force:
|
26
|
+
create_table "g5_updatable_clients", force: :cascade do |t|
|
27
27
|
t.string "uid"
|
28
28
|
t.string "urn"
|
29
29
|
t.json "properties"
|
@@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20141222072623) do
|
|
36
36
|
add_index "g5_updatable_clients", ["uid"], name: "index_g5_updatable_clients_on_uid", using: :btree
|
37
37
|
add_index "g5_updatable_clients", ["urn"], name: "index_g5_updatable_clients_on_urn", using: :btree
|
38
38
|
|
39
|
-
create_table "g5_updatable_locations", force:
|
39
|
+
create_table "g5_updatable_locations", force: :cascade do |t|
|
40
40
|
t.string "uid"
|
41
41
|
t.string "urn"
|
42
42
|
t.string "client_uid"
|
@@ -50,7 +50,7 @@ ActiveRecord::Schema.define(version: 20141222072623) do
|
|
50
50
|
add_index "g5_updatable_locations", ["uid"], name: "index_g5_updatable_locations_on_uid", using: :btree
|
51
51
|
add_index "g5_updatable_locations", ["urn"], name: "index_g5_updatable_locations_on_urn", using: :btree
|
52
52
|
|
53
|
-
create_table "restaurants", force:
|
53
|
+
create_table "restaurants", force: :cascade do |t|
|
54
54
|
t.string "name"
|
55
55
|
t.string "client_uid"
|
56
56
|
t.datetime "created_at"
|