g5_updatable 0.6.1 → 0.7.0

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: 03bbbe2a39869e50aa5f682c13e57ece6a2ecaae
4
- data.tar.gz: d157e9bac448852de34f502ad587c89d5b50e2d3
3
+ metadata.gz: eb73a50f2ccd171abc638c249de6ac44691d3767
4
+ data.tar.gz: 6c31e1de5ebae2044c3aff58d6fddcf7d7936c63
5
5
  SHA512:
6
- metadata.gz: 5078737e13d73325f43920c4f276a03655e69b8b0f5de6b6ec3d47cbed049edc506e23f6cb9f955ca6172c9a4a5823d810785e10163a161bd348050a1ee19b8d
7
- data.tar.gz: 1c63962a14563eb4b39477c90f2ab69306224965c6a2152d8012b5a813a287a7dff332dcb31dafe8deb71fc4af3c0bd2660ad1451ea0146611f7668cdb712c31
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
@@ -1,3 +1,3 @@
1
1
  module G5Updatable
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -1,11 +1,9 @@
1
1
  development:
2
2
  adapter: postgresql
3
3
  database: g5_updatable_dummy_development
4
- username: g5
5
- password: rocks!
4
+ user: vagrant
6
5
 
7
6
  test:
8
7
  adapter: postgresql
9
8
  database: g5_updatable_dummy_test
10
- username: g5
11
- password: rocks!
9
+ user: vagrant
@@ -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: true do |t|
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: true do |t|
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: true do |t|
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: true do |t|
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"