forced 1.1.1 → 1.2.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 +25 -5
- data/app/models/forced/client.rb +3 -3
- data/lib/forced/version.rb +2 -2
- data/lib/forced/versionable.rb +1 -1
- data/lib/generators/forced/templates/create_forced_tables.rb.erb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16c4c3bfcdfca6854aff43e3155e3e34102b36dc
|
4
|
+
data.tar.gz: a1157c7f545af0f270bf9a7c669f929884c82552
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64b4a7a5081e2288eb4019eb5e83e14a94eab16d52147a5fe5b07871006e93fe089efa382f8bb5d4b45a89865cda3903f03217c34414cb1de5263a2a5c76b233
|
7
|
+
data.tar.gz: 8d1fbe32b4928fcff4d93c12c4092b1a7589413125e935aa3e96256f8f888fdca53f1f11d88c08c8703cf8b2c89e6e0ed3bf0e85d2e07f486f5869bdf4c8ed01
|
data/README.md
CHANGED
@@ -42,7 +42,7 @@ You endpoint and tables are set!
|
|
42
42
|
|
43
43
|
## Usage
|
44
44
|
|
45
|
-
If you want a parent for your `Forced::Client` records, you can add the desired parent model
|
45
|
+
If you want a parent for your `Forced::Client` records, you can add `is_versionable` to the desired parent model. Beware that both `Forced::Client` to `Forced::Version` relation and `is_versionable` to `Forced::Client` relation are set to `dependent: :destroy`.
|
46
46
|
|
47
47
|
The `Forced::Client`'s polymorphic relation is optional as well. So, you can use the gem without setting a parent class relation. It'll work exactly the same.
|
48
48
|
|
@@ -67,7 +67,7 @@ Brand.find(:id).clients
|
|
67
67
|
# => #<ActiveRecord::Associations::CollectionProxy [...]>
|
68
68
|
|
69
69
|
Brand.find(:id).clients.to_sql
|
70
|
-
# => "SELECT
|
70
|
+
# => "SELECT "forced_clients".* FROM "forced_clients" WHERE "forced_clients"."owner_id" = :id AND "forced_clients"."owner_type" = 'Brand'"
|
71
71
|
```
|
72
72
|
|
73
73
|
The Forced module needs to get the coming request to prepare the response. As long as request headers contains `X-Platform` and `X-Client-Version`, you are good to go.
|
@@ -91,11 +91,31 @@ If you want to return some version of this hash, you can access the response by
|
|
91
91
|
response = Forced::Response.call(request)
|
92
92
|
```
|
93
93
|
|
94
|
-
To
|
94
|
+
To change the default response from the mounted endpoint, create a `StatusController` like below.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# In order this to work,
|
98
|
+
# you need to create this file in the correct path,
|
99
|
+
# that is;
|
100
|
+
#
|
101
|
+
# app/controllers/forced/status_controller.rb
|
102
|
+
|
103
|
+
module Forced
|
104
|
+
class StatusController < ::ApplicationController
|
105
|
+
def index
|
106
|
+
response = Forced::Response.call(request)
|
107
|
+
|
108
|
+
# Do what you want to do with the response hash.
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
To create a record, you can use your Rails console. `Forced::Client` is polymorphic and keeps `foreign_key` and `foreign_type` columns as `owner_#`. So, when you are creating a `Forced::Client` instance, use `owner:` for your reference column, e.g. `Forced::Client.create(owner: Brand.first)`
|
95
115
|
|
96
116
|
```ruby
|
97
117
|
Forced::Client.new
|
98
|
-
# => #<Forced::Client id: nil,
|
118
|
+
# => #<Forced::Client id: nil, owner_type: nil, owner_id: nil, identifier: nil, deleted_at: nil, created_at: nil, updated_at: nil>
|
99
119
|
|
100
120
|
Forced::Version.new
|
101
121
|
# => #<Forced::Version id: nil, client_id: nil, version: nil, force_update: false, changelog: nil, deleted_at: nil, created_at: nil, updated_at: nil>
|
@@ -105,7 +125,7 @@ Forced::Version.new
|
|
105
125
|
|
106
126
|
All available under `Forced::MESSAGES` hash table. You can override the values as you wish. Also checkout the `check_update_status` private method in `base.rb` to understand the cases.
|
107
127
|
|
108
|
-
## Upgrading from 0.2.0 to 1.
|
128
|
+
## Upgrading from 0.2.0 to 1.2.0
|
109
129
|
|
110
130
|
New migrations and tables have a different name, so, unless you are using custom calls, you can optionally and gradually create a migration for old table and move your records into the new table.
|
111
131
|
|
data/app/models/forced/client.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Table name: forced_clients
|
4
4
|
#
|
5
5
|
# id :integer not null, primary key
|
6
|
-
#
|
7
|
-
#
|
6
|
+
# owner_type :string
|
7
|
+
# owner_id :integer
|
8
8
|
# identifier :string
|
9
9
|
# deleted_at :datetime
|
10
10
|
# created_at :datetime not null
|
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
module Forced
|
15
15
|
class Client < ApplicationRecord
|
16
|
-
belongs_to :
|
16
|
+
belongs_to :owner, polymorphic: true, optional: true
|
17
17
|
|
18
18
|
has_many :versions, class_name: 'Forced::Version', foreign_key: 'client_id', dependent: :destroy
|
19
19
|
end
|
data/lib/forced/version.rb
CHANGED
data/lib/forced/versionable.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
class CreateForcedTables < ActiveRecord::Migration<%= migration_version %>
|
5
5
|
def change
|
6
6
|
create_table :forced_clients<%= forced_table_options %> do |t|
|
7
|
-
t.references :
|
7
|
+
t.references :owner, polymorphic: true, index: true
|
8
8
|
t.string :identifier, index: { unique: true }
|
9
9
|
t.datetime :deleted_at
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aoozdemir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|